I have this piece of code, which is an event handler of a button1's click.
private void button1_Click(object sender, EventArgs e)
{
string str = "trj\0klk";
textBox1.Text =c.ToString() ;
}
As you can see in the previous code, i want to write "trj\0klk" string in the textBox1, but when i run this application, only "trj" appear in textBox1, because the compiler thought the character "\0" (the fourth character) is the null terminator character, so it stoped reading the string when reached it. How can I solve this problem?
Loading

Jorge L FernandezRank #7,688 · 236 reputationPosted Nov 9, 2009, 12:11 PM EST
const string NULL = " ";
string theValue = "example\0next"
TextBox1.Text = theValue.Replace("\0",NULL);
// This Sample will show "example next"
This will solve your problem. Set the NULL variable with the char you want to represent in the control.
Mohamed Sidi Mohamed7 reputationPosted Nov 9, 2009, 1:13 PM EST
Thanks.
My best wishes.
Jorge L FernandezRank #7,688 · 236 reputationPosted Nov 9, 2009, 1:25 PM EST
Try this
string myValue = @"example\0next";
TextBox1.Text = myValue;
// Should show exaclty "example\0next"
Mohamed Sidi Mohamed7 reputationPosted Nov 9, 2009, 1:46 PM EST
\\0 and \0 are very different, when you put @ before the string, the textbox will read null character as two characters: backslash and '0' characters, and that 's not what i want.
Mohamed Sidi Mohamed7 reputationPosted Nov 9, 2009, 1:47 PM EST
\\0 and \0 are very different, when you put @ before the string, the textbox will read null character as two characters: backslash and '0' characters, and that 's not what i want.
Thanks.
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 9, 2009, 5:22 PM EST
This will work for you.
string str = "trj\\0klk";
textBox1.Text = str.ToString();
But I dont know it's what you want.
If this helps, please accept my answer.