Use the Marshal.PtrToStringAnsi function.
- Atul
Sky Software
http://www.ssware.com/
Drop-In Windows Explorer-Like Shell Browsing UI for your apps.
"David" <(E-Mail Removed)> wrote in message
news:73A7AA9A-092F-4A35-9875-(E-Mail Removed)...
>I have a byte array that contains a whole bunch of information in it. It
> gets generated from an embedded device and sent to me over ethernet.
>
> Among the elements of information in that byte array is a C-style string.
> In other words, there are 16 bytes. Each byte contains an ASCII
> character,
> or 0. The string is null terminated.
>
> I want to load those characters into a .NET string object. Is there a
> single call that can do that?
>
> I thought that ASCIIEncoding.ASCII.GetString(array, startindex, 16) would
> do
> it for me. However, if the byte array contains the ascii character 'b',
> followed by 15 zeros, what I want is the string "b", a string with length
> 1.
> What I get is a string "b/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0", a string with
> length 16, in which the first character is the unicode 'b', and the others
> are the unicode null character.
>
> After failing to find a function that would do it, I just wrote a function
> that took such a string and stripped out the first null and anything after
> it, and that worked. However, it seemed to me that this would be a common
> enough operation that there is probably a function call that did it in one
> call, which would result in better code. Is there such a function?