0

Does anyone know how is the following possible? All of a sudden string comparison using .ToLower and Lcase stopped working.

If I do this in the immediate window:

?lcase(text)
"menu"
?lcase(text)="menu"
False

This just started a few minutes ago. I'm using:

  • .NET 4.5.2
  • Visual Studio 2013 Ultimate
  • Visual Basic

EDIT: The source of this problem is from here:Please how can i return decoded bytes instead of text from a CryptoStream

After making that code change.

Community
  • 1
  • 1
Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157

2 Answers2

4

First of all, I would stop using LCase because it is VB 6 compability code.

Second I would not use .NETs build in "string".ToLower() or "string".ToUpper() in string comparisons because that can lead to some unexpected results for some locals.

Better use text.Equals("menu", StringComparison.OrdinalIgnoreCase)

I don't know what the root cause of your problem is, but hope that helps.

Jürgen Steinblock
  • 30,746
  • 24
  • 119
  • 189
0

Take a look at String.Compare

'Declaration
Public Shared Function Compare ( _
    strA As String, _
    strB As String, _
    ignoreCase As Boolean _
) As Integer

Result Less than zero = strA is less than strB.
Result Zero = strA equals strB.
Result Greater than zero = strA is greater than strB.

mattumotu
  • 1,436
  • 2
  • 14
  • 35