We help IT Professionals succeed at work.
Get Started

In-line CHR(0) truncates a VB.NET String

cdwdirect
cdwdirect asked
on
760 Views
Last Modified: 2012-06-27
I work with a lot of IEEE-compressed single-precision floating point data in fixed-length record file formats.  A field containing a compressed Single as stored in the file is four bytes of (normally) non-plaintext ASCII characters.  They often include one or more NULL-zero characters in any of the four byte positions.  The .NET framework seems to be behaving inconsistently when those four bytes are loaded into a string.

90% of the time a string is truncated at the first Chr(0) character in the character sequence. Yes... 90% of the time. It depends on the context. If you return the string BYVAL, for example, the .NET runtime cuts it down. However, if you use a StringBuilder and then convert and assign it to a string with StringBuilderVar.ToString() then Chr(0)'s do NOT cause the destination string to be truncated. But then StringVar.Substring(iOffset, iLen) DOES truncate the results if it contains a Chr(0)!

Can this behavior be avoided?  Is there a special version of the string variable that I can use that doesn't try and "fix" my string for me?  I would like to continue using strings if possible, since they are one of the best features of the BASIC language.  As it is, it is almost like I am coding in C because I'm having to do things one character at a time using character arrays.
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 3 Answers and 9 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE