Identifying the next character in a string is capital or not
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 advanceYou 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.
精彩评论