04-04-2012 02:05 PM
I am experiencing an issue passing strings to and from a .NET assembly through the LabVIEW .NET interface. I am calling a method that takes a string input. I am passing a binary data stream directly from Read from Binary File and then reading it back from another method. I can confirm that the assembly received the data and it thinks it's sending it back to me, but I only receive an empty string. Looking more closely at the data, I discovered that the first character of the data stream is a null character. If I use a simple ASCII string, I don't have any problems. If I precede the binary string with a simple ASCII string, the string is returned up until it hits the null character. I don't know C#, but apparently it doesn't use null terminated strings. So why does the LabVIEW .NET interface assume that the string is null terminated? Is this a bug, or is there a reason it works this way?
The code snippet doesn't actually work, but it illustrates what I'm talking about. The x=y? would be false, and the empty? would be true.
Thanks,
Chris
04-04-2012 05:12 PM
Using a NUL to terminiate a string is fairly common in most of the programming languages. Both C and C++ use NULLS to terminate strings. Many standard string functions don't handle binary data very well specifically because of this. I suspect that somewhere in the lower levels of the code (.NET or even the LabVIEW nodes) standard string functions are being called and the data is then truncated at the first NULL character.