locked
Is vb code read string case sensitive? RRS feed

  • Question

  • User546194788 posted

    Here is my code.

    Is vb code read string case sensitive?

    In USER table there three users.

    Name IsActive
    AAA Yes
    BBB YES
    CCC No

    -----------------------

    dim strIsActive as string = ""

    strIsActive =retrive_data_from_user_table("IsActive").tostring

     if strIsActive <> "Yes"  then message "Your are not active user"  //  return BBB and CCC

    ------------------------

    As my thought that BBB is active user also but return to "not active user"

    Wednesday, July 22, 2020 12:26 PM

Answers

  • User475983607 posted

    String comparison in VB is case sensitive.   This is a trivial concept to test...

    Imports System
    
    Module Program
        Sub Main(args As String())
            Console.WriteLine("Yes".ToLower() = "YES".ToLower())
            Console.WriteLine("Yes" = "YES")
        End Sub
    End Module

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2020 12:39 PM
  • User753101303 posted

    Hi,

    It is case sensitive by default but it can be configured. See for example https://www.techrepublic.com/blog/smb-technologist/visual-studio-compiler-options-part-3-option-compare/

    In this particular case I would use a boolean rather than a string (your database doesn't have a boolean type ?) or maybe even a datetime depending on the exact purpose (for example to know also since when a user account was disabled etc...)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2020 12:42 PM
  • User546194788 posted

    Thank you both of you.

    I never know it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2020 12:46 PM

All replies

  • User475983607 posted

    String comparison in VB is case sensitive.   This is a trivial concept to test...

    Imports System
    
    Module Program
        Sub Main(args As String())
            Console.WriteLine("Yes".ToLower() = "YES".ToLower())
            Console.WriteLine("Yes" = "YES")
        End Sub
    End Module

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2020 12:39 PM
  • User753101303 posted

    Hi,

    It is case sensitive by default but it can be configured. See for example https://www.techrepublic.com/blog/smb-technologist/visual-studio-compiler-options-part-3-option-compare/

    In this particular case I would use a boolean rather than a string (your database doesn't have a boolean type ?) or maybe even a datetime depending on the exact purpose (for example to know also since when a user account was disabled etc...)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2020 12:42 PM
  • User546194788 posted

    Thank you both of you.

    I never know it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 22, 2020 12:46 PM