Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try something like the following. You will have to replace regex_pattern with your regular expression pattern. In your case, regex_pattern should be something like <code>@"\\s\\d\\dC"</code> (a whitespace character (<code>\\s</code>) followed by a digit (<code>\\d</code>) followed by a digit (<code>\\d</code>) followed an upper-case letter <code>C</code>.</p> <p>You may also wish to remove the <code>NSRegularExpressionCaseInsensitive</code> option if you can be sure that the letter C will never be lower case.</p> <pre><code>NSError *error = nil; NSString *regex_pattern = @"\\s\\d\\dC"; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regex_pattern options:(NSRegularExpressionCaseInsensitive | NSRegularExpressionDotMatchesLineSeparators) error:&amp;error]; NSArray *arrayOfMatches = [regex matchesInString:myString options:0 range:NSMakeRange(0, [myString length])]; // arrayOfMatches now contains an array of NSRanges; // now, find and extract the 2nd match as an integer: if ([arrayOfMatches count] &gt;= 2) // be sure that there are at least 2 elements in the array { NSRange rangeOfSecondMatch = [arrayOfMatches objectAtIndex:1]; // remember that the array indices start at 0, not 1 NSString *secondMatchAsString = [myString substringWithRange: NSMakeRange(rangeOfSecondMatch.location + 1, // + 1 to skip over the initial space rangeOfSecondMatch.length - 2)] // - 2 because we ignore both the initial space and the final "C" NSLog(@"secondMatchAsString = %@", secondMatchAsString); int temperature = [secondMatchAsString intValue]; // should be 32 for your sample data NSLog(@"temperature = %d", temperature); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload