Domanda

I have to develop a Windows Mobile C# app to compare chars and get the ascii code

This is my pseudocode:

    public void getAscii(char c) 
    {
        int ascii_n = c.GetAscii(); //or something that gives me the hexadec number
        //You know; a=97, b=98...

        if (ascii_n > 12 && ascii_n < 23)
        { 
            //code lines
        }
        else if (ascii_n > 24 && ascii_n < 55)
        {
            //more code lines
        }
    }

Any idea about how can I do it??

È stato utile?

Soluzione

You don't need an hex representation of a char, just a conversion to an integer could be enough

char c = '\n';
int ascii_n = (int)c;
Console.WriteLine(ascii_n);   // = 10

also for char higher than 255

char c = '∙';
int a = (int)c;
Console.WriteLine(a);   // = 8729
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top