D
devgrt
C#:
I have a buffer that is populated with char data from a DLL:
byte [] ret = new byte[1024];
I want to convert to a C# string:
string msg = Encoding.ASCII.GetString(ret, 0, ret.Length);
The problem is I never know in advance what size the string will be. When I
call Encoding.ASCII.GetString I need to specify the size. If I set it to
ret.Length as above then in the debugger I can see msg is the full 1024
bytes (0 padded at the end regardless of the actual string's size).
How can I look at a byte[] and determine the size of the string in it (I
know I could just loop and look for the first occurance of 0 -- is tha tthe
best way?)
Thank you!
I have a buffer that is populated with char data from a DLL:
byte [] ret = new byte[1024];
I want to convert to a C# string:
string msg = Encoding.ASCII.GetString(ret, 0, ret.Length);
The problem is I never know in advance what size the string will be. When I
call Encoding.ASCII.GetString I need to specify the size. If I set it to
ret.Length as above then in the debugger I can see msg is the full 1024
bytes (0 padded at the end regardless of the actual string's size).
How can I look at a byte[] and determine the size of the string in it (I
know I could just loop and look for the first occurance of 0 -- is tha tthe
best way?)
Thank you!