How to 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 the line "2Hello" added. How to get a line in this "Hello" form?

+4
source share
2 answers

Use char instead:

 char stx = '\u0002'; 

or

 char stx = (char) 2; 

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

Anyway, just use:

 StringBuilder builder = new StringBuilder(mystring); builder.Append(stx); 
+11
source
 builder.Append((char)stxval); 

otherwise it will just add int.ToString()

+1
source

All Articles