Re: Getting Rid of the Nulls

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: J.Marsch (jeremy_at_ctcdeveloper.com)
Date: 04/20/04


Date: Tue, 20 Apr 2004 13:59:18 -0500

Jon:

I think that this is also a documentation error:
The help says this:
"If trimChars is a null reference (Nothing in Visual Basic), white space
characters are removed instead."

We are not confusing '\0' with null -- those are certainly different things.
However, What I get from the help is that if I pass null, _all_ whitespace
characters should be removed: '\0', a space, '\t', \n', '\l' and so on.
Whereas if I pass '\0', I expect it to look for the null char only.

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1ae63fdd9c0d23ca98a68b@msnews.microsoft.com...
> Drew <someone@hotmail.com> wrote:
> > I have been using System.Text.Encoding.Unicode.GetString(byte[],0,72)
> > to converter a byte array from the registry to a string.
> >
> > This works, but I end up with a bunch of null characters after
> > the "good" string data that I need to parse. This is evidenced
> > by the fact that string.length returns 36 when the actual string
> > data I need to work with is usually much less.
>
> If the actual string is less than 36 characters, why are you decoding
> 72 bytes? Where did the number 72 come from?
>
> > I tried using String.Trim(null) but this doesn't achieve the desired
result.
>
> No, it wouldn't. A null reference isn't the same as a null character,
> \0. String.Trim('\0') should be fine though.
>
> > The only thing I can think of is to convert the string to a char array
> > and loop through until I hit a null character.
> >
> > Is there a better way to get rid of the nulls?
> >
> > If I could just get the actual length of the string that would help.
>
> Registry strings are always null-suffixed - so you can just decode two
> bytes fewer in order to avoid having a null at the end of the string.
> However, it doesn't sound like this was your real problem, if the data
> is "usually much less".
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



Relevant Pages

  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: algorithm to compare 3 array elements
    ... but the back reference doesn't. ... So if you make the regex global (adding ... return string; ... characters, and not skipping the first two. ...
    (comp.lang.javascript)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)
  • Re: Delimiting problems
    ... prcise it is the reference to the beginning of the string. ... > What is the above code to delimit new lines before characters? ... "LISP is worth learning for the profound enlightenment experience ...
    (comp.lang.c)
  • Re: Instrrev function
    ... then goes totwo characters. ... So to get the column reference ... Hope this is noted by Microsoft. ... "Returns the position of an occurrence of one string within another, ...
    (microsoft.public.excel.programming)