I have a textview that already has text extracted from a website. So, let’s say the text in the text view has this text:
Save Location
84°F
Clear
Feels like 90°F
In this text, how can I extract the text that says 84 in the “84°F” to a string? Remember that the 84 is a constantly changing variable from the website so sometimes it’ll be a different number and I can’t search for the number directly. If you know how to do this please let me know 🙂 Thanks for your time.
Try something like this:
Now
stringWithNumswill contains something like this:Then you could parse
stringWithNumslike this:finalTemperaturewill contain “84”. You could put this in method form and pass inoriginalStringas an argument so you could reuse this code. Hope this helps and if you have any questions, make sure to ask in the comments!UPDATE:
I added this line:
&& [[tempArray objectAtIndex:index] intValue] < 200
to the if statement above, so it now looks like this:
In the website text, it looks like the only number before the “82” is a zip code, which is 5 digits long. In reality, all temperatures (on Earth) are below 200 (3 digits), so the extra line I put in makes sure that the final temperature is a three or less digit number and not a 5 digit zip code.
Hope this helps!