I'm having serious problems with string-handling. As my problems are rather hard to describe, I will start with some demo code reproducing them:
Dim s1 As String = "hi"
Dim c(30) As Char
c(0) = "h"
c(1) = "i"
Dim s2 As String = CStr(c)
s2 = s2.Trim()
If not s1 = s2 Then
MsgBox(s1 + " != " + s2 + Environment.NewLine + _
"Anything here won't be printed anyway..." + Environment.NewLine + _
"s1.length: " + s1.Length.ToString + Environment.NewLine + _
"s2.length: " + s2.Length.ToString + Environment.NewLine)
End If
The result messagebox looks like this:
The reason that this comparison fails is that s2 has the length 31 (from the original array-size) while s1 has the length 2.
I stumble over this kind of problem quite often when reading string-information out of byte-arrays, for example when handling ID3Tags from MP3s or other encoded (ASCII, UTF8, ...) information with pre-specified length.
Is there any fast and clean way to prevent this problem?
What is the easiest way to "trim" s2 to the string shown by the debugger?