VB.NET Char() and VBFixedString

Hi:

How do I get rid of null chars in a Char() or a String? I have the following Structure and code and the result of it is a String tailling by space (or null?).  For example, if the output is supposed to be "ABC", "ABC             " (13 space/nulls) is outputed instead. And Trim() is not working. Please help. Thanks.

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> Public Structure DATA
        <VBFixedString(16), MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)> Public ABBR As Char()
End Structure

Dim d As DATA
Dim mystring As String
....
d = CType(Marshal.PtrToStructure(New IntPtr(tBankScan), GetType(DATA)), DATA)
mystring = d.ABBR
Console.WriteLine("""" & mystring.TrimEnd & """")

sdc248Asked:
Who is Participating?
 
bchoorCommented:
maybe:

mstring.TrimEnd(chr(0))
0
 
bchoorCommented:
Another thought, Trim function, when called without any parameters, only removes characters that are considered whitespace. To determine whether that space is deemed as whitespace - run this:

Debug.WriteLine(Char.IsWhiteSpace(mystring, 5))   ' Basically seeing if the 5th character in the string is considered whitespace. If it returns false, then you'll need to find out the ascii number of the character:

Debug.WriteLine(ASC(Substring(mystring, 5,1)) - let's say the answer is 0

then you would

mystring.trimend(chr(0))
0
 
sdc248Author Commented:
Right on.
0
 
sdc248Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.