Problem to remove \0 in the array in the best way

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a windows C# app which read data through socket from a C++ app in a
linux box. After a marshal a pointer and get an array of string ends with \0,
I did something like this

string s=new string(array);
s = s.Replace("\0","");
if(s == "ABC")
success
else
fail

However, if I did it in my test all in C#, it works. If I plug into the
production and start to listen to the linux box messages, it always fail. If
Studio's output window, I can see s becomes ABC~ instead of ABC.

Does anyone here know what is the most efficient way to solve this problem?
I do can iterate the array to detect \0, but I do want the most efficient way
since I am facing a very heavy traffic from that linux box.

Thanks a lot

Chris
 
Thanks. Actually, I checked the input again and realize there is more than /0
in the input. That is a 5 byte array, after converting to char array, it
shows as below in debu window

{Length=5}
[0]: 65 'A'
[1]: 73 'B'
[2]: 89 'C'
[3]: 0 ''
[4]: 732 '˜'
Any idea about what is going on?

Thanks
 
Back
Top