A String Problem

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

Guest

void myfunction(String * Parameter){
String* test0 = S"A"; // Parameter is also "A",but its details is not
very clear.

String *test1 = String::Format(S"head{0}tail",test0);
// the test1 is "headAtail"
String *test2 = String::Format(S"head{0}tail",Parameter);
// the test2 is "headA" , the charactors following A are all cut.}

I guess the Parameter has a terminative '\0' ,but I am not quite sure of
that.(The Watch Pannel shows that it is just a "A");
What 's the possible reason of this? How to avoid it?
 
void myfunction(String * Parameter){
String* test0 = S"A"; // Parameter is also "A",but its details is not
very clear.

String *test1 = String::Format(S"head{0}tail",test0);
// the test1 is "headAtail"
String *test2 = String::Format(S"head{0}tail",Parameter);
// the test2 is "headA" , the charactors following A are all cut.}

I guess the Parameter has a terminative '\0' ,but I am not quite sure of
that.(The Watch Pannel shows that it is just a "A");
What 's the possible reason of this? How to avoid it?

I suspect you'll find that test2 is *actually* headA\0tail, but that
what you're using to display it is stopping as soon as it sees a \0.
The best fix for this is to try to work out why you're getting a \0 in
the first place, and avoid it. Otherwise, you can use String.Trim,
passing in \0 as the character to trim.
 
Thank you!!


TrimEnd(S"\0"->ToCharArray()) can solve the problem.



“Jon Skeet [C# MVP]â€ç¼–写:
 
Back
Top