Re: Getting Rid of the Nulls
From: J.Marsch (jeremy_at_ctcdeveloper.com)
Date: 04/20/04
- Next message: Daniel O'Connell [C# MVP]: "Re: The language wars - round 3"
- Previous message: Patrick de Ridder: "Process.Start question"
- In reply to: Jon Skeet [C# MVP]: "Re: Getting Rid of the Nulls"
- Next in thread: Jon Skeet [C# MVP]: "Re: Getting Rid of the Nulls"
- Reply: Jon Skeet [C# MVP]: "Re: Getting Rid of the Nulls"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Daniel O'Connell [C# MVP]: "Re: The language wars - round 3"
- Previous message: Patrick de Ridder: "Process.Start question"
- In reply to: Jon Skeet [C# MVP]: "Re: Getting Rid of the Nulls"
- Next in thread: Jon Skeet [C# MVP]: "Re: Getting Rid of the Nulls"
- Reply: Jon Skeet [C# MVP]: "Re: Getting Rid of the Nulls"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|