StringBuilder question : Adding ASCII control schars ?

S

Sagaert Johan

Hi

I am construncting a string containing some control chars (STX/ETX)

I noticed that adding a byte with value 2 is the same as adding a character
'2' ???

How can i solve this problem ?
Is the stringbuilder restricted to pure readable ascii code contents ?


sb.Append(2); // ascii code 2
sb.Append('2'); // ascii char '2'



Johan
 
V

Vijaye Raji

In the case of sb.Append(2), the compiler is picking the overload

StringBuilder Append (int value);

If you want the "2" to be treated as the ASCII value of the character, you
want it to pick the overload

StringBuilder Append (char value);

Try this:

sb.Append ((char) 2);

-vJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top