|
-
Sep 15th, 2007, 07:38 AM
#1
Thread Starter
Lively Member
[2.0] Ascii codes
How could I get the ascii code of a character not within the KeyDown, KeyUp or KeyPress. I have a data in the clipboard and want to read it if separated by Enter key to paste it into the DataGridView column cells .
-
Sep 15th, 2007, 07:46 AM
#2
Re: [2.0] Ascii codes
I am confused what event are you using? And you want the ascii character to go into the DataGridView?
Code:
char c = (char)67;
textBox1.Text = c.ToString();
That will produce C...
and to reverse it...
Code:
int i;
char a = 'C';
i = (int)a;
textBox1.Text = i.ToString();
Last edited by Paul M; Sep 15th, 2007 at 08:03 AM.
-
Sep 15th, 2007, 09:33 PM
#3
Re: [2.0] Ascii codes
Just note that casting between int and char will give you Unicode values, not ASCII. They are the same for most ASCII characters, and certainly for the most common, but not for all. You can also use Convert.ToInt32 and Convert.ToChar for the same result. If want genuine ASCII values then you'd have to decode a string using an ASCIIEncoding object and then read the byte values.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|