newbie: nullterminated array's to string ?

  • Thread starter Thread starter dtdev
  • Start date Start date
D

dtdev

When translating a char array to a string, does C# treats bytevalue 0x00 as
terminator as in C ?

I have an char array with strings that ends with 0x00 as stringterminator -
if ToString() doesnt work with this, what should i do instead ?
 
dtdev said:
When translating a char array to a string, does C# treats bytevalue 0x00 as
terminator as in C ?
No.

I have an char array with strings that ends with 0x00 as stringterminator -
if ToString() doesnt work with this, what should i do instead ?

If it's only got 0x00 after the end of the real string, you can use
x = x.TrimEnd('\0');

Otherwise you can use IndexOf to find the first occurence, and then
Substring to get only the bit you want to use.
 
Back
Top