ASCII values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Colbert

    #1

    ASCII values

    Simple but potentially dumb question:

    How can I get the ASCII numeric value for a character in C#? In FoxPro, the
    function ASC("A") returns a 65 (int). Is there a similar function in C#?

    Thanks in advance.

    Dan Colbert
    Senior Process Engineer
    JDA eHealth Systems, Inc.


  • Jon Skeet [C# MVP]

    #2
    Re: ASCII values

    Dan Colbert <dcolbert@jdaeh ealth.com> wrote:[color=blue]
    > Simple but potentially dumb question:
    >
    > How can I get the ASCII numeric value for a character in C#? In FoxPro, the
    > function ASC("A") returns a 65 (int). Is there a similar function in C#?[/color]

    Just cast the character to an int, and it will give you the Unicode
    value. (You don't actually need the cast unless you're distinguishing
    between overloads.) The Unicode value of any ASCII character is the
    same as its ASCII value.

    For instance:

    int i = 'a'; // i is now 65.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Dan Colbert

      #3
      Re: ASCII values

      Thanks!

      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1a2c1f f0bcc3d52f989b2 3@msnews.micros oft.com...[color=blue]
      > Dan Colbert <dcolbert@jdaeh ealth.com> wrote:[color=green]
      > > Simple but potentially dumb question:
      > >
      > > How can I get the ASCII numeric value for a character in C#? In FoxPro,[/color][/color]
      the[color=blue][color=green]
      > > function ASC("A") returns a 65 (int). Is there a similar function in[/color][/color]
      C#?[color=blue]
      >
      > Just cast the character to an int, and it will give you the Unicode
      > value. (You don't actually need the cast unless you're distinguishing
      > between overloads.) The Unicode value of any ASCII character is the
      > same as its ASCII value.
      >
      > For instance:
      >
      > int i = 'a'; // i is now 65.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      Working...