Filter Out Null Characters

Sometimes when a user pastes, my app receives a null character (ascii 00) at the end of the string.

Is there an easy way to filter this out? Trim doesn’t seem to apply to nulls.

Replaceall with chr(0)?

That’s my thought too: s = s.ReplaceAll(&u0,"")

I love good, simple ideas. :slight_smile:

Wonder if Trim should replace nulls on either end.

You can filter out NULL but perhaps will happen that other “gremlins” will be pasted.
So why not write a method to clean strings from unwanted chars?

This maybe a year later, but thanks of the tip on ReplaceAll(&u0,"").

I had a parser application in which the parser worked great, but a TextArea used to display the original file was choking on the NULL characters. A piece of hardware would output this NULL characters in some cases, and these were playing havoc with the parser display. Yet if I took the text data and re-saved it in Notepad, everything displayed just fine. I finally nailed it down to this extra characters, and this thread completed the puzzle. Thanks again.

[quote=23695:@Stephen Dodd]Sometimes when a user pastes, my app receives a null character (ascii 00) at the end of the string.

Is there an easy way to filter this out? Trim doesn’t seem to apply to nulls.[/quote]

result = ReplaceAllB(string,chr(0))

Simple ReplaceAll probably does not always work.

[quote=122744:@Michel Bujardet]result = ReplaceAllB(string,chr(0))

Simple ReplaceAll probably does not always work.[/quote]

Keep in mind that the encoding may employ null bytes as part of a code point – for example, UTF-16 does whereas UTF-8 does not. Usually your strings will be UTF-8 encoded in which case removing null bytes with ReplaceAllB is safe, but with a different encoding ReplaceAllB might reduce the string to gibberish.

Good point. I never use UTF16, but then it seems this would be better :

cool, I didn’t now &u syntax.