Search code examples
iphonensscanner

nscanner taking value from a string


how can i get the value of pickey from this string.this string as such is stored in coredata and i need to extract the value of pickey.how can i do this using nscanner.which method should i use?

@"http://myserverIP/[email protected]&key=442205212&hash=63b201cacb5c07f6adbc8f3dcb408099d3450548&pickey=21342342342342341231"

Solution

  • NSScanner *scanner = [NSScanner scannerWithString:myString];
    [scanner scanUpToString:@"pickey=" intoString:NULL];
    if ([scanner scanString:@"pickey=" intoString:NULL]) {
        long long pickeyValue = 0;
        if ([scanner scanLongLong:&pickeyValue]) {
            // Successfully found an integer value at this position
            ...
        }
    }