'iOS return one digit fragment from NSString
I can't find an easy way to generate a one digit sized substring from an NSString. The NSString looks like "(N3)" but I need to store just the number portion "3" in an substring. Using:
NSString *subString = [dis substringFromIndex:2];
returns "3)".
Any ideas?
Solution 1:[1]
Well, if the string is one digit and its position is invariant, you could just use:
int Foo(NSString * dis) {
const unichar c = [dis characterAtIndex:2];
assert(isdigit(c) && "not a number");
return c - '0';
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | justin |
