VB.NET Char() and VBFixedString


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 & """")

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

sdc248Author Commented:
Right on.
sdc248Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.