Jeff Yeager
Jeff Yeager

Reputation: 61

String Length Issues

I have a byte array that I convert into a string like so Dim byt As Byte() = New Byte(255) {} s = New String(Encoding.ASCII.GetChars(byte)) My question is when I look at the string in a debuger its clearly a normal string but when I compare it to what I know its supposed to be it doesnt equal. So i did a quick check and for some reason its return a string thats the length of 256 characters. So i did a s.trim and it still is 256 characters long. Any idea whats going on what this?

Upvotes: 0

Views: 252

Answers (1)

Hans Passant
Hans Passant

Reputation: 941277

You created a string with 256 characters that are 0. The debugger cannot display them. Use this to trim the string:

   s = s.Trim(ChrW(0))

Upvotes: 1

Related Questions