Extract only DIGIT in Objective c I have string this, Total Bill : $22.00, I just want to extract 22 from this string, i'm confused how to get that, I have tried some code but it gives me 2200 rather than 22. My code is this, 
 NSString * val = @"Total Bill : $22.00";
NSString *newString = [[val componentsSeparatedByCharactersInSet:
[[NSCharacterSet decimalDigitCharacterSet] invertedSet]]
componentsJoinedByString:@""];
NSLog(@"VV %@",newString);


The simplest is to find the location of the $ and then return the rest of the string. This will give you the 22.00.
NSString *val = @"Total Bill : $22.00";
NSRange dollar = [val rangeOfString:@"$"];
NSRange decimal = [val rangeOfString:@"."];
if (dollar.location != NSNotFound && decimal.location != NSNotFound) {
    NSRange range = NSMakeRange(dollar.location + 1, decimal.location - dollar.location - 1)
    NSString *amount = [val substringWithRange:range];
    NSLog(@"VV %@",amount);
} else {
    NSLog(@"No dollar sign or decimal found");
}


One option is to use a NSCharacterSet union with the characters you want to keep (currency separator -- decimal point in your case).. then invert it. Split the string and then join it using this character set. Then you can use NSNumberFormatter to get the result..
NSString *stringToParse = @"Total Blah: $22.00";
NSMutableCharacterSet *characterSet = [NSMutableCharacterSet decimalDigitCharacterSet];
[characterSet formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".,"]];
stringToParse = [[stringToParse componentsSeparatedByCharactersInSet:[characterSet invertedSet]] componentsJoinedByString:@""];

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
[formatter setMinimumFractionDigits:0];
[formatter setMaximumFractionDigits:0];
[formatter setPartialStringValidationEnabled:YES];

NSString *str = [formatter stringFromNumber:[formatter numberFromString:stringToParse]];

NSLog(@"%@", str);


You can use NSScanner to extract values like this from a string. 
Depending on the type you want, you can use scanDouble:, scanInt: or something else. Here's an example:
    NSString *myString = @"Total Bill : $22.00";

    NSScanner *scanner = [[NSScanner alloc] initWithString:myString];

    // Moves the scanner to the "$" character, then eats that character
    [scanner scanUpToString:@"$" intoString:nil];
    [scanner scanString:@"$" intoString:nil];

    // Here you have options, can scan as a double or an integer, or convert later.
    double val = 0;
    [scanner scanDouble:&val];