I'm a C/C++ guy trying to learn C# and I'm converting some of my C code into C# for learning.
In the following snippet of code, the char array temp[] gets initialized as nulls '\0'. If I turn the array into a string object using the string constructor, the nulls become char data instead of the terminator I'd expect. Subsequent string operations don't go as planned...
However this is what strout comes up as: "0000000000\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\012345"Code:char[] temp = new char[30]; // initialized as nulls '\0' int z; for(z=0; z<10; z++) temp[z] = '0'; // temp should be "0000000000" string strout = new string(temp); // create string from array of 0's strout += "12345"; // should now be "000000000012345"
How do I make those nulls get treated as a string terminator?
Thanks




Reply With Quote