You can use NSScannerto get the value and the rest of the string.
NSString *input = @"123alpha";
NSScanner *scanner = [NSScanner scannerWithString:input];
float number;
[scanner scanFloat:&number];
NSString *rest = [input substringFromIndex:[scanner scanLocation]];
If it’s important to know exactly what remains after parsing the value, this is a better approach than trying to trim characters. Although I cannot come up with any specific bad input at that point that could not offer the solution proposed by the OP in the commentary to this, it looks like a pending error will occur.
source
share