Recognize integers in string

Is there a command that can recognize whether a character in the string is a integer? I have to write a function that does the following:

This function returns true if its parameter is a syntactically valid path, and false otherwise. A syntactically valid path is a sequence of zero or more path segments (not separated by spaces, commas, or anything else). Here are two syntactically valid paths: N2e1E01n0e2e1 and W42. Here are four strings that are not syntactically valid paths: sn3, e1x, N144, and w2+n3. Notice that a path may be syntactically valid without being traversible in a particular grid.

My idea is to read the first character of the string. If it's equal to N,n,S,s,W,w,E,e then it would move on to the next character else the function would return false. Here is where I need a command that can recognize if the character is an integer. If it's an integer it will move on to the next character. If that character is an integer or N,n,S,s,W,w,E,e then it continues to the next character and so on. The function will continue until the index is less than the string size or until it fails a condition test.
There is indeed a function that checks whether a character in a string is a digit!
http://cplusplus.com/reference/clibrary/cctype/isdigit/

NOTE: Decimal digits only.

-Albatross
Is it possible to use isdigit with a switch/case? I tried the following and it won't let me because
case isdigit(path[index]):
isn't a constant.

switch (path[index])
	{
		case 'N':
		case 'n':
		case 'S':
		case 's':
		case 'W':
		case 'w':
		case 'E':
		case 'e':
			index++;
			break;
		default:
			return 0;
	}
	
	for(index;index != path.size();index++)
	{
		switch (path[index])
		{
			case 'N':
			case 'n':
			case 'S':
			case 's':
			case 'W':
			case 'w':
			case 'E':
			case 'e':
			case isdigit(path[index]):
				break;
			default:
				return 0;
		}
	}
Sorry, only constants are allowed in cases. So no, you can't. You could just add the few digit cases as well though:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	switch (path[index])
	{
		case 'N':
		case 'n':
		case 'S':
		case 's':
		case 'W':
		case 'w':
		case 'E':
		case 'e':
			index++;
			break;
		default:
			return 0;
	}
	
	for(index;index != path.size();index++)
	{
		switch (path[index])
		{
			case 'N':
			case 'n':
			case 'S':
			case 's':
			case 'W':
			case 'w':
			case 'E':
			case 'e':
			//case isdigit(path[index]):
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
				break;
			default:
				return 0;
		}
}
Thanks, totally forgot that was an option since I only have to test for those 10 digits.
Topic archived. No new replies allowed.