Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How shall i add control character to string

int stxval = 0x02; //found this value on wikipedia
string mystring = "Hello";

StringBuilder builder = new StringBuilder(mystring);
builder.Append(stxval);

Here in string builder "2Hello" is appended. how to get string in this form "Hello"?

like image 733
cmj Avatar asked Dec 12 '22 09:12

cmj


1 Answers

Use char instead:

char stx = '\u0002';

or

char stx = (char) 2;

Personally I prefer the first option, but it's up to you.

Anyway, then just use:

StringBuilder builder = new StringBuilder(mystring);
builder.Append(stx);
like image 197
Jon Skeet Avatar answered Dec 14 '22 21:12

Jon Skeet