How to find ASCII value of first character in a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishnaneeraja
    New Member
    • Mar 2008
    • 21

    How to find ASCII value of first character in a string

    Hi,
    im developing one web application using asp.net,c#.net. In that i want to find ASCII value of first character in a string.plz help me.



    thanks.
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    Hi ,

    in C# to find the ascii value of the character u can use
    Console.Write(C onvert.ToString (Convert.ToInt3 2('a'));
    convert.ToInt32 ('a') gives u the ascii value
    it displayes u 97 (ascii value)



    Originally posted by krishnaneeraja
    Hi,
    im developing one web application using asp.net,c#.net. In that i want to find ASCII value of first character in a string.plz help me.



    thanks.

    Comment

    • malav123
      New Member
      • Feb 2008
      • 217

      #3
      HI krishna,
      You can use substring function and extract one character from the string i.e. first character and store it in one character variable and then use ascii function on that character variable, your problem will be solved.....

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        This is a pretty easy one.
        Code:
        string mystr="Fred ran fast.";
        int myASCIIValue = (int)mystr[0];
        //myASCIIValue is now 70

        Comment

        Working...