Asc in C#?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chua Wen Ching

    #1

    Asc in C#?

    Hi there.

    VB6 had this function called Asc('a')

    So how can i code that function in c#? I want to return
    an int.

    Regards,
    Chua Wen Ching :p
  • phoenix

    #2
    Re: Asc in C#?

    Just convert the char to an int

    char a = 'a';
    int asc = a; // First way
    int asc2 = Convert.ToInt32 (a); // Second way

    Yves

    "Chua Wen Ching" <chuawenching@c huawenching.com > schreef in bericht
    news:065d01c348 76$11caccb0$a50 1280a@phx.gbl.. .[color=blue]
    > Hi there.
    >
    > VB6 had this function called Asc('a')
    >
    > So how can i code that function in c#? I want to return
    > an int.
    >
    > Regards,
    > Chua Wen Ching :p[/color]


    Comment

    • Quizical

      #3
      Re: Asc in C#?

      Phoenix, this was my first response for this problem also, but if you
      get into the extended asc values somewhere around 130 + or - 20, there
      becomes a very distinct difference in the way that it works. I would
      advise pulling in the VisualBasic name space and use the VB.Net asc().
      It will work properly for you then.

      "phoenix" <patient0@skyne tWORK.be> wrote in message news:<#Dd$C6HSD HA.1720@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
      > Just convert the char to an int
      >
      > char a = 'a';
      > int asc = a; // First way
      > int asc2 = Convert.ToInt32 (a); // Second way
      >
      > Yves
      >
      > "Chua Wen Ching" <chuawenching@c huawenching.com > schreef in bericht
      > news:065d01c348 76$11caccb0$a50 1280a@phx.gbl.. .[color=green]
      > > Hi there.
      > >
      > > VB6 had this function called Asc('a')
      > >
      > > So how can i code that function in c#? I want to return
      > > an int.
      > >
      > > Regards,
      > > Chua Wen Ching :p[/color][/color]

      Comment

      • Jon Skeet

        #4
        Re: Asc in C#?

        Quizical <CodeQuestioner @yahoo.com> wrote:[color=blue]
        > Phoenix, this was my first response for this problem also, but if you
        > get into the extended asc values somewhere around 130 + or - 20, there
        > becomes a very distinct difference in the way that it works. I would
        > advise pulling in the VisualBasic name space and use the VB.Net asc().
        > It will work properly for you then.[/color]

        No - it's just a case of working out what you *really* mean. "Asc"
        suggests "ASCII" to me, and there *are* no ASCII values about 127.
        However, what you *may* actually want is the default system encoding
        for a character, in which case using Encoding.Defaul t is the best way
        to go.

        See http://www.pobox.com/~skeet/csharp/unicode.html for more details.

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

        • Chua Wen Ching

          #5
          Re: Asc in C#?

          Use unicode???

          But i always thought that unicode is different with ascii!

          Thanks for the link.

          Regards,
          Chua Wen Ching :p

          Comment

          • Chua Wen Ching

            #6
            Re: Asc in C#?

            Thanks. The article help me to clear my thoughts.

            Regards,
            Chua Wen Ching :p

            Comment

            • Chua Wen Ching

              #7
              Re: Asc in C#?

              Hi,

              Will there be a performance drop if use the VB style Asc
              in C#?

              And what is AscW() functionality?

              Thanks for the replies.

              Regards,
              Chua Wen Ching :p

              Comment

              • Michael \(michka\) Kaplan [MS]

                #8
                Re: Asc in C#?

                "Chua Wen Ching" <chuawenching@c huawenching.com > wrote...
                [color=blue]
                > Will there be a performance drop if use the VB style Asc
                > in C#?[/color]

                Yes, there will, because you will be loading the entire VB compat library,
                for the sake of a single function.
                [color=blue]
                > And what is AscW() functionality?[/color]

                It returns the Unicode code point value, rather than Asc (which converts the
                Unicode character to the default system code page and returns the code
                point's number).


                --
                MichKa [MS]

                This posting is provided "AS IS" with
                no warranties, and confers no rights.



                Comment

                • Michael \(michka\) Kaplan [MS]

                  #9
                  Re: Asc in C#?

                  The article is indeed wrong -- extended ASCII is a fictional concept, made
                  up by people/products who do not truly understand what ASCII is.


                  --
                  MichKa [MS]

                  This posting is provided "AS IS" with
                  no warranties, and confers no rights.


                  "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
                  news:uSGnUxZSDH A.2316@tk2msftn gp13.phx.gbl...[color=blue]
                  >[color=green]
                  > >Please,Pleas e Don't propagate crap! You get one point for the asc =
                  > >ASCII, -10 for bad info and references.[/color]
                  >
                  > I guess that means you score something like -100 then, because this
                  > article ...
                  >
                  >[color=green]
                  > >Check out this page as a reference!
                  > >
                  > >http://aspnet.4guysfromrolla.com/art...91802-1.3.aspx[/color]
                  >
                  >
                  > ... is pretty bad. You just have to see code like this
                  >
                  > char ctmp = (strPwd.Substri ng((a % intLength),1).T oCharArray()[0]);
                  >
                  > to realize that the author doesn't know what he's doing. And I
                  > wouldn't want to use an encryption algorithm implementation that uses
                  > Chr and Asc.
                  >
                  >
                  >
                  > Mattias
                  >
                  > --
                  > Mattias Sjögren [MVP] mattias @ mvps.org
                  > http://www.msjogren.net/dotnet/
                  > Please reply only to the newsgroup.[/color]


                  Comment

                  • Jon Skeet

                    #10
                    Re: Asc in C#?

                    Quizical <CodeQuestioner @yahoo.com> wrote:

                    <snip>
                    [color=blue]
                    > ASCII, pronounced "ask-key", is the common code for microcomputer
                    > equipment. The standard ASCII character set consists of 128 decimal
                    > numbers ranging from zero through 127 assigned to letters, numbers,
                    > punctuation marks, and the most common special characters. The
                    > Extended ASCII Character Set also consists of 128 decimal numbers and
                    > ranges from 128 through 255 representing additional special,
                    > mathematical, graphic, and foreign characters.
                    >
                    > Check out this page as a reference![/color]

                    Doesn't prove a thing. I'll readily accept that there are many people
                    out there who believe that the particular 8-bit encoding they prefer is
                    "the extended ASCII character set" - but many of them will be
                    different. It's like people saying that something is encoded in "the"
                    EBCDIC character encoding, when in fact there are many varieties of
                    that, too.

                    Just because something is widely believed doesn't mean it's true. Lots
                    of people have believed in the past (hopefully fewer believe now) that
                    Java passes objects by reference, for instance - that doesn't make it
                    true.

                    Of course, if you could point to an international standards body which
                    claims that the particular extension you prefer is *the* extended ASCII
                    character set, that would lend some more credence to your claims.

                    (Just for reference, the first PC I used came with a rather good
                    manual, which included *lots* of different code pages in the back.
                    IIRC, the one which you deem to be "the" extended ASCII table is code
                    page 437. There are plenty of others, however, and 437 wasn't the
                    default for all countries.)

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

                    • ozbear

                      #11
                      Re: Asc in C#?

                      On 13 Jul 2003 15:26:36 -0700, CodeQuestioner@ yahoo.com (Quizical)
                      wrote:
                      [color=blue]
                      >Jon Skeet <skeet@pobox.co m> wrote in message news:<MPG.197a5 ed0b7eac26498a0 c3@news.microso ft.com>...[color=green]
                      >> Quizical <CodeQuestioner @yahoo.com> wrote:[color=darkred]
                      >> > Phoenix, this was my first response for this problem also, but if you
                      >> > get into the extended asc values somewhere around 130 + or - 20, there
                      >> > becomes a very distinct difference in the way that it works. I would
                      >> > advise pulling in the VisualBasic name space and use the VB.Net asc().
                      >> > It will work properly for you then.[/color]
                      >>
                      >> No - it's just a case of working out what you *really* mean. "Asc"
                      >> suggests "ASCII" to me, and there *are* no ASCII values about 127.
                      >> However, what you *may* actually want is the default system encoding
                      >> for a character, in which case using Encoding.Defaul t is the best way
                      >> to go.
                      >>
                      >> See http://www.pobox.com/~skeet/csharp/unicode.html for more details.[/color]
                      >
                      >Please,Pleas e Don't propagate crap! You get one point for the asc =
                      >ASCII, -10 for bad info and references.
                      >
                      >ASCII - The American Standard Code for Information Interchange is a
                      >standard seven-bit code that was proposed by ANSI in 1963, and
                      >finalized in 1968. Other sources also credit much of the work on ASCII
                      >to work done in 1965 by Robert W. Bemer (www.bobbemer.com). ASCII was
                      >established to achieve compatibility between various types of data
                      >processing equipment. Later-day standards that document ASCII include
                      >ISO-14962-1997 and ANSI-X3.4-1986(R1997).
                      >[/color]

                      Please take your own advise and don't post/propagate crap.

                      Your reference to the ASCII standard is correct and defines
                      codes 0->127 just as Jon Skeet says.

                      Your other reference is irrelevant, no matter what it says,
                      because it does not originate from the same standards body.

                      Oz

                      Comment

                      • Quizical

                        #12
                        Re: Asc in C#?

                        > ... is pretty bad. You just have to see code like this[color=blue]
                        >
                        > char ctmp = (strPwd.Substri ng((a % intLength),1).T oCharArray()[0]);
                        >
                        > to realize that the author doesn't know what he's doing. And I
                        > wouldn't want to use an encryption algorithm implementation that uses
                        > Chr and Asc.[/color]

                        I'll grant you this, I would not write a line of code that way. Second,
                        I bet at some point even as an end user you used the RC4 algorithm, that said :P

                        Comment

                        • Quizical

                          #13
                          Re: Asc in C#?

                          "Michael \(michka\) Kaplan [MS]" <michkap@online .microsoft.com> wrote in message news:<uvcXBtaSD HA.2852@tk2msft ngp13.phx.gbl>. ..[color=blue]
                          > The article is indeed wrong -- extended ASCII is a fictional concept, made
                          > up by people/products who do not truly understand what ASCII is.
                          >
                          >
                          > --
                          > MichKa [MS][/color]
                          fic·tion Pronunciation Key (fkshn) n.

                          1.) An imaginative creation or a pretense that does not represent
                          actuality but has been invented.

                          http://msdn.microsoft.com/library/de...cter_codes.asp

                          I guess you just posted fic·tion... And you work for microsoft... Are
                          they fiction too? " people/products who do not truly understand what
                          ASCII" How do they make M&M's? Why are man holes round? Try those out
                          tough guy.

                          Comment

                          • Jon Skeet

                            #14
                            Re: Asc in C#?

                            Quizical <CodeQuestioner @yahoo.com> wrote:[color=blue]
                            > fic·tion Pronunciation Key (fkshn) n.
                            >
                            > 1.) An imaginative creation or a pretense that does not represent
                            > actuality but has been invented.
                            >
                            > http://msdn.microsoft.com/library/de...library/en-us/
                            > vclang98/html/_pluslang_ascii _character_code s.asp
                            >
                            > I guess you just posted fic·tion... And you work for microsoft... Are
                            > they fiction too? " people/products who do not truly understand what
                            > ASCII" How do they make M&M's? Why are man holes round? Try those out
                            > tough guy.[/color]

                            Yes, MS is wrong on this. It's not the only thing in MSDN that's
                            incorrect, I'm sure. (I can think of another example immediately,
                            actually, to do with the singleton pattern implementation in C#.) As I
                            said before, it's a widespread belief, but that doesn't make it
                            correct.

                            Now, if you could post a link to a *standards* document which defines
                            "extended ASCII" that would be much more convincing.

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

                            Working...