Strange Bug in VB 2005
That's THE strangest bug I ever encountered while working with Visual Basic. Ever!
I was parsing a list of strings that was separated by a
And then I went to my loop:
Apparently the last item of the array, instead of being and empty string, is a
The ONLY way I could find to workaround this stuff was changing my test line to look like this:
However when examined in the "Quick Watch" window it does show
I was parsing a list of strings that was separated by a
CR/LF
pair. Something like this:The quick brown fox jumped over the lazy dog.[CR][LF]So, I used the following command to get an array of strings:
Miss Piggy sent Kermit an email.[CR][LF]
Lois was cheating on Clark[CR][LF]
Dim aStrList as String() = _Simple, right?
strFullList.Replace(vbLf, "").Split(vbCr)
And then I went to my loop:
For Each strItem As String In aStrListThe first time I ran it it crashed my code. I took me some time to discover why.
If (strItem = "") Then
Exit For
End If
'... do whatever...
Next
Apparently the last item of the array, instead of being and empty string, is a
String
which contains a single "character" Nothing
.The ONLY way I could find to workaround this stuff was changing my test line to look like this:
If (strItem.Chars(0) = Nothing) ThenFor the sake of completion, this strange string has the following properties:
Test | Result |
---|---|
strItem = "" | False |
strItem = Nothing | False |
strItem.Length = 0 | False |
strItem.Length = 1 | True |
However when examined in the "Quick Watch" window it does show
strItem
as an empty string.
0 Comments:
Post a Comment