locked
Creating a case sensitive parameter RRS feed

  • Question

  • User521235944 posted

    Hello, I was wondering if there was a way to create a parameter for a method in VB.NET 2005, to select which case(upper, lower) to test for. 


    For Example

    Function Afunction1 (ByVal aString As String, ByVal case As ......) As Boolean

    End Function


    Where case is the paramter for the user to set as upper or lower.

    Monday, November 9, 2009 1:36 PM

Answers

  • User521235944 posted

    Thanks, I had forgotten about Enums.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 9, 2009 4:23 PM

All replies

  • User-1285286688 posted

    TimBue,

    Not sure what it is in VB.NET however you can use the IndexOf function on a string.

    Something like

    int index = aString.IndexOf(case);


    It will return -1 if the character does not have a match in the string.

    Hope this helps,

    --Scott

    Monday, November 9, 2009 2:00 PM
  • User521235944 posted

    I don't think I explained what I was after clear enough.


    Basically I would like to know how to create the parameter in the signature of the function, not the test within the code itself.  I know I can use IsUpper or IsLower to test the case of the string passed,  however what I need is to be able to let the user specify in the specific case required to test in the parameter such as the following


    Call AFunction1(textbox1.text, uppercase)

    how should I declare the uppercase parameter in the signature of the function.  Or do I have to use a boolean type, or integer type as the second parameter?


    Monday, November 9, 2009 3:03 PM
  • User-1285286688 posted

    I think a bool or an int is going to be way to do this.  


    --Scott

    Monday, November 9, 2009 3:31 PM
  • User-1412642538 posted

    Something like this comes to (my) mind:


    Enum InputCase

          Upper = 1

          Lower = 2

    End Enum


    Function Whatever(sString as string, i as InputCase)


    End Function



    Monday, November 9, 2009 4:16 PM
  • User521235944 posted

    Thanks, I had forgotten about Enums.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 9, 2009 4:23 PM