Asc equivalent?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Z

    #1

    Asc equivalent?

    Hello folks,

    Does anyone know the equivalent VB Asc function for C#?

    Or ways around it?


    Thanks in advance
    Pete


  • Jon Skeet

    #2
    Re: Asc equivalent?

    Peter Z <peter_zahos@pr imus.com.au> wrote:[color=blue]
    > Does anyone know the equivalent VB Asc function for C#?
    >
    > Or ways around it?[/color]

    Could you say *exactly* what you want to do? Note that the value of any
    char is its unicode value - and if the character is an ASCII character,
    that will be exactly the ASCII value.

    If you want to know the value of any character in the system's default
    code page, you should look at using Encoding.Defaul t.

    --
    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

    • Peter Z

      #3
      Re: Asc equivalent?

      Marvellous effort that!


      "NULL" <Thomas-dot-Delrue-at-Tiscali-dot-Be> wrote in message
      news:s1u8lvckj8 l7cg6lcb60edvbk i63sbsqja@4ax.c om...[color=blue]
      > On Tue, 2 Sep 2003 18:48:39 +0800, "Peter Z"
      > <peter_zahos@pr imus.com.au> wrote:
      >[color=green]
      > >Hello folks,
      > >
      > >Does anyone know the equivalent VB Asc function for C#?
      > >
      > >Or ways around it?[/color]
      >
      > try this
      >
      > int nASCII = (int)'A'; //should give 65 or 91 or something like
      > //that...?
      > int nASCII2 = (int)myCharVari able;
      > int nASCII3 = (int)myString[1]; //second char in string[/color]


      Comment

      • Jon Skeet

        #4
        Re: Asc equivalent?

        NULL <Thomas-dot-Delrue-at-Tiscali-dot-Be> <NULL <Thomas-dot-Delrue-at-
        Tiscali-dot-Be>> wrote:[color=blue][color=green]
        > >Marvellous effort that![/color]
        >
        > What do you mean?
        >
        > It is simple as 1-2-4 (sorry, 1-2-3 :) )
        > just like in C, C++ (etc.) a char is a datatype of 1 byte[/color]

        Um, no. char is a datatype of *2* bytes...

        --
        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

        • NULL

          #5
          Re: Asc equivalent?

          On Tue, 2 Sep 2003 13:55:47 +0100, Jon Skeet <skeet@pobox.co m> wrote:
          [color=blue]
          >NULL <Thomas-dot-Delrue-at-Tiscali-dot-Be> <NULL <Thomas-dot-Delrue-at-
          >Tiscali-dot-Be>> wrote:[color=green][color=darkred]
          >> >Marvellous effort that![/color]
          >>
          >> What do you mean?
          >>
          >> It is simple as 1-2-4 (sorry, 1-2-3 :) )
          >> just like in C, C++ (etc.) a char is a datatype of 1 byte[/color]
          >
          >Um, no. char is a datatype of *2* bytes...[/color]

          Unicode? Ah... didn't know that...
          anyway, the conversion still works :)

          Comment

          • NULL

            #6
            Re: Asc equivalent?

            On Tue, 2 Sep 2003 13:55:47 +0100, Jon Skeet <skeet@pobox.co m> wrote:
            [color=blue]
            >NULL <Thomas-dot-Delrue-at-Tiscali-dot-Be> <NULL <Thomas-dot-Delrue-at-
            >Tiscali-dot-Be>> wrote:[color=green][color=darkred]
            >> >Marvellous effort that![/color]
            >>
            >> What do you mean?
            >>
            >> It is simple as 1-2-4 (sorry, 1-2-3 :) )
            >> just like in C, C++ (etc.) a char is a datatype of 1 byte[/color]
            >
            >Um, no. char is a datatype of *2* bytes...[/color]

            Jon Skeet said:[color=blue][color=green]
            >>Note that the value of any char is its unicode value[/color][/color]

            Yeah, should have known that one :)

            --
            NULL

            Comment

            • NULL

              #7
              Re: Asc equivalent?

              On Wed, 3 Sep 2003 07:11:21 +0800, "Pete Z" <peter@infovisi on.com.aj>
              wrote:
              [color=blue]
              >It's a way of saying thankyou![/color]

              :D
              np (sorry, a bit too much hours wihtout sleep I guess. :S sorry)
              [color=blue]
              >
              >
              >"NULL" <Thomas-dot-Delrue-at-Tiscali-dot-Be> wrote in message
              >news:nlv8lv4uh jm8s8gaa7gaef21 j6bjb8gqnb@4ax. com...[color=green]
              >> On Tue, 2 Sep 2003 19:22:16 +0800, "Peter Z"
              >> <peter_zahos@pr imus.com.au> wrote:
              >>[color=darkred]
              >> >Marvellous effort that![/color]
              >>
              >> What do you mean?
              >>
              >> It is simple as 1-2-4 (sorry, 1-2-3 :) )
              >> just like in C, C++ (etc.) a char is a datatype of 1 byte, that can be
              >> converted to any other (native) datatype that is larger (int, short,
              >> long, byte, etc...) by just casting it...
              >> You can also try this:
              >>
              >> int nASCII = Convert.ToInt32 ('A');
              >> long lASCII = Convert.ToInt64 ('B');
              >> short sASCII = Convert.ToInt16 ('C'); //short==16 bits? (I though so)
              >>
              >> --
              >> NULL
              >>[color=darkred]
              >> >"NULL" <Thomas-dot-Delrue-at-Tiscali-dot-Be> wrote in message
              >> >news:s1u8lvckj 8l7cg6lcb60edvb ki63sbsqja@4ax. com...
              >> >> On Tue, 2 Sep 2003 18:48:39 +0800, "Peter Z"
              >> >> <peter_zahos@pr imus.com.au> wrote:
              >> >>
              >> >> >Hello folks,
              >> >> >
              >> >> >Does anyone know the equivalent VB Asc function for C#?
              >> >> >
              >> >> >Or ways around it?
              >> >>
              >> >> try this
              >> >>
              >> >> int nASCII = (int)'A'; //should give 65 or 91 or something like
              >> >> //that...?
              >> >> int nASCII2 = (int)myCharVari able;
              >> >> int nASCII3 = (int)myString[1]; //second char in string[/color]
              >>[/color]
              >[/color]

              Comment

              Working...