Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Individual Character

Status
Not open for further replies.

Skute

Programmer
Jul 21, 2003
272
GB
Hi,

how can i set a variable to the value of a specific ASCII code?

ie, in visual basic its possible todo something like this:

string strDelimiter = chr(27)

How can i do that in C#?
 
This should do something of what you want:

Code:
String strDelimiter = System.Convert.ToString((char)27);
 
it'd be good to take note that john's solution works in loads of languages without much adjustment. chars and ints (or bytes etc.) can often be casted as each another.
 
ah excellent, thanks, the current method i used is this:

private char cDelim = (new ASCIIEncoding()).GetChars(new byte[]{27})[0];


Is your method better?
 
That also works in reverse as well..
Code:
char c = (char)97;
// c == 'a'

int i = (int)c;
// i == 97
Be careful because the moment you get a unicode character it all goes to pot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top