Creating a char or String from ascii code

P

Phil Mc

Hi
Can anyone tell me how to create an instance of a char or string from
an ascii character code.

That is if I wont to create a tab char (code 0009), how would I achieve
this.

I know about the slash characters \t and \n etc. but I need to be able
to do this manually.


Thanks
 
T

Truong Hong Thi

Hi Phil,
I am not very sure what you meant with "manually", but it seems you
wanted some thing like this:
either
char c = '\u0009';
or
char c = '\x0009'
will work.
More on the C# lang spec.

Thi - http://thith.blogspot.com
 
J

Jon Skeet [C# MVP]

Phil said:
Can anyone tell me how to create an instance of a char or string from
an ascii character code.

The easiest way is just to cast it:

int i = 9;
char c = (char)i;

Call ToString on the char to get a string.

Jon
 

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