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?
+1
A:
The following expression is true if and only if myChar is within myString:
[myString rangeOfString: [NSString stringWithFormat: @"%c", myChar]
options: NULL].location != NSNotFound
Jon Rodriguez
2010-10-17 23:37:50
+6
A:
You can use the rangeOfString message on the NSString:
NSRange rng = [string rangeOfString:@"."];
if (rng.location != NSNotFound)
// "." is in the string at position rng.location
Cannonade
2010-10-17 23:38:03
Just an addition. I used this and even with a heap of NSLogs confirming correct data NSNotFound didn't work as expected. The link below has a solution IF you have this problem.
Rudiger
2010-10-18 01:40:56
@Rudiger Thanks man. I checked out the linked answer and up-voted it :)
Cannonade
2010-10-18 01:47:30