Is it possible to extract a number from a string. For example, I have a line:
my name is shishir and my number is 98890876478
Is it possible to extract from 98890876478the specified string?
Or if my line is:
my name is shishir and my number is XXX98890876478XXX
In this state, I can retrieve "98890876478", which is between XXX.
Can this be done?
I get a message from the server, which should be in the format as indicated above, and I need a numeric value for further operations
Edit:
Here is the code I'm trying to use:
NSString *logString = [NSString stringWithFormat:@"%@",theXML];
NSString *digits = [logString stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];
NSLog(@"Message id: %i", [digits intValue]);
which outputs:
2010-05-21 16:37:07.092 sms[5311:207] OK: message-ID XXX110103468XXX
2010-05-21 16:37:07.851 sms[5311:207] Message id: 2
I think its return is two, because size == 2. I need to get the value between "XXX".
source
share