is a character already in the range
Hi everybody! I need to get, is a character already in the range. The character string is of type NSMuttableString.
For example, I have a string of "52.648" and I need to know is a "." symbol is already in the string. How can I do it? Thanx!
There are many methods in the NSString class for searching strings. You'll find the documentation here:
You can find the position of a substring with:
NSRange r = [string rangeOfString:@"."];
if ( r.location != NSNotFound ) {
bla bla bla
}
If you're simply wanting to convert that string to a double you can use the doubleValue method (and or intValue/longValue, boolValue floatValue for atoi type conversion).
double d = [string doubleValue];
If you know the stardard C library functions (strlen,strstr and so on), you can use them:
char* theBytes [string UTF8String];
if ( strchr(theBytes,'.') ) {
bla bla;
}
I do NOT recommend using the C library functions, however they might help you transition from the familiar land of C to the much more charming (and slightly mysterious) world of Objective-C and Cocoa.