Results 1 to 3 of 3

Thread: [2.0] Ascii codes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    Angry [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 .

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width