0
public static bool CheckIdentifier(String i)
        {
            bool state = false;
            char[] c = i.ToCharArray();
            try
            {
                if (Convert.ToInt32(c[0]) >= 65 && Convert.ToInt32(c[0]) <= 90 || Convert.ToInt32(c[0]) == 95 || Convert.ToInt32(c[0]) >= 97 && Convert.ToInt32(c[0]) <= 122)
                {
                    for (int Index = 0; Index < c.Length; Index++)
                    {
                        if (Convert.ToInt32(c[Index]) >= 48 && Convert.ToInt32(c[Index]) <= 57 || Convert.ToInt32(c[Index]) >= 65 && Convert.ToInt32(c[Index]) <= 90 || Convert.ToInt32(c[Index]) == 95 || Convert.ToInt32(c[Index]) >= 97 && Convert.ToInt32(c[Index]) <= 122)
                            state = true;
                        else
                        {
                            return false;
                        }
                    }
                }
                return state;
            }
            catch
            { return false; }
        }        {
2
Contributors
1
Reply
24
Views
2 Years
Discussion Span
Last Post by ddanbe
1

Hi Muhammad 90, welcome at DaniWeb.
Line 9 should be for(int index = 1 . . . index 0(the first char) is already checked on line 7.
The code checks to see if the string is an identifier. The first char must be a letter, followed by letters or digits. Look at an ASCII table for the codes used e.g. 65 to 90 are the capital letters from 'A' to 'Z'. This could bemade simpler by using the Is Letter and IsDigit methods of the char type.

Edited by ddanbe: addition

Votes + Comments
sir kindly can you make it simple???
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.