Reputation: 50
OK so I don't get yelled at I did search the forums and there is a very similar question, I'm just having a little difficulty understanding what is meant.
I'm generating a random number in decimal, checking to see if it matches a certain exclusion range for characters I don't want to print, if it does not match the exclusion range, I save the int and I want to send it to the char to be printed.
I don't know how to tell visual studio to print the decimal integer 65 as the char "A" heres my code:
int asciVal = rnd.Next(33, 96);
if (asciVal == 48 || asciVal == 49 || asciVal == 50 || asciVal == 51 || asciVal == 52 || asciVal == 53 || asciVal == 54 || asciVal == 55 || asciVal == 56 || asciVal == 57 || asciVal == 65 || asciVal == 66 || asciVal == 67 || asciVal == 68 || asciVal == 69 || asciVal == 70 || asciVal == 71 || asciVal == 72 || asciVal == 73 || asciVal == 74 || asciVal == 75 || asciVal == 76 || asciVal == 77 || asciVal == 78 || asciVal == 79 || asciVal == 80 || asciVal == 81 || asciVal == 82 || asciVal == 83 || asciVal == 84 || asciVal == 85 || asciVal == 86 || asciVal == 87 || asciVal == 88 || asciVal == 89 || asciVal == 90)
loop = 1;
else {
loop = 0;
Text = asciVal;
}
Upvotes: 0
Views: 672
Reputation: 11
You can use the unicode in c#.
int asciival= <value>;
char letter = (char) asciival;
string word = letter.ToString();
Upvotes: 1
Reputation: 1132
Use Convert.ToChar
int number = 65;
char c = Convert.ToChar(number);
Upvotes: 4
Reputation: 1324
The simplest way to convert an ascii int to char is the following:
int i = 123;
char c = (char)i;
Upvotes: 1