Re: Getting Rid of the Nulls

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


Date: Tue, 13 Apr 2004 11:01:18 -0500

Drew:

It looks as though Andreas has your root problem fixed. If you still need
to perform the trim, you can use
string newString = oldString.Trim('\0') (note the single quotes, not double
quotes)

I'm not sure why String.Trim(null); doesn't work. According to the help, it
should be exactly what you are after.

"Drew" <someone@hotmail.com> wrote in message
news:uJW2moWIEHA.3356@TK2MSFTNGP11.phx.gbl...
> 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.
>
> I tried using String.Trim(null) but this doesn't achieve the desired
result.
>
> 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.
>
> Thanks,
>
> Drew
>
>
>
>



Relevant Pages

  • Re: Mandis Quotes (aka retiring """ and )
    ... > surround the string by a pair of doubled single quotes. ... > an arbitrary string in-between the single quotes which does NOT ... > of ASCII or Unicode characters, but instead as a sequence of lines ...
    (comp.lang.python)
  • 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: Mandis Quotes (aka retiring """ and )
    ... >surround the string by a pair of doubled single quotes. ... > of ASCII or Unicode characters, but instead as a sequence of lines ... Quoting "arbitrary" text also involves the issue of encoding, ...
    (comp.lang.python)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... put them in stupid places. ... Programming is difficult (as you must surely appreciate, ... > strings will be in the range 1...1000 characters. ... impose an artificially small limit on string length." ...
    (comp.programming)
  • Re: A note on personal corruption as a result of using C
    ... impossible to write effective string validation routines by definition ... (Note that a string literal may contain embedded null characters; ... without resorting to abusive language. ... In practice, programmers typically use "struct" ...
    (comp.programming)