开发者

Identifying the next character in a string is capital or not

开发者 https://www.devze.com 2023-02-15 12:34 出处:网络
I am writing a C++ program. I have an array of char array trans[20][100]. Actually each string of trans is a transition of a grammar(Programming language transl开发者_如何学JAVAators). I want to check

I am writing a C++ program. I have an array of char array trans[20][100]. Actually each string of trans is a transition of a grammar(Programming language transl开发者_如何学JAVAators). I want to check for each string in trans whether there is a Non-terminal after a '.' i.e. i want to check if in the strings there is a '.' followed by any capital letter. Can anyone please tell me how to do it??

-Thanks in advance


You can use any RegExp library (e.g. this one). The test regular expression is /\.[A-Z]/.

Or for ASCII string you can use:

int strHasDotCap(const char *s)
{
    while (*s) {
        if (*s++ == '.') {
            if (*s >= 'A' && *s <= 'Z') return 1;
        }
    }
    return 0;
}


You can use the functions in ctype.h isAlpha(), isUpper() etc. if the characters are ASCII type.


If you operate on ASCII char, then you could test if the int value of the char is between 65 and 90. See the ASCII table.

0

精彩评论

暂无评论...
验证码 换一张
取 消