Delete part of a string
Posted: 08 May 2017 09:18
So I'm getting weather from an .xml file every morning and save it to a variabel. 3 exapemls of the text,
"Sun and clouds mixed. Slight chance of a rain shower. High 3C. Winds NNE at 25 to 40 km/h."
"Partly cloudy skies during the evening will give way to cloudy skies and light freezing rain after midnight. Low -10C. NNE winds shifting to WSW at 15 to 25 km/h. Chance of precip 50%."
"Showers early becoming a steady light rain later in the day. Snow may mix in. High 2C. Winds WNW at 10 to 15 km/h. Chance of rain 80%."
What I want to do is to remove the wind part, eg.
Winds NNE at 25 to 40 km/h
NNE winds shifting to WSW at 15 to 25 km/h
Winds WNW at 10 to 15 km/h
If I get the Regular expression syntax right, then I should be able to delete from "Wind" to "km/h" and then have something to delete the direction. At the moment I'm ruining this,
day=replaceAll("{day}", "(SSW )|(SW )|(W )|(NNW )|(NW )|(N )|(NNE )|(NE )|(E )|(Winds )|(shifting )|(at )|[0-9][0-9] to [0-9][0-9]|(km/h)", " ");
which is not optimal. I have been trying to find how to write it, but the syntax doesn't help much. (nor that the notification for nougat doesn't work, so I have to use tts to find what the string contain. I found no good option to find what the variabels contain except the global ones, but tts is faster than to check that every time.)
"Sun and clouds mixed. Slight chance of a rain shower. High 3C. Winds NNE at 25 to 40 km/h."
"Partly cloudy skies during the evening will give way to cloudy skies and light freezing rain after midnight. Low -10C. NNE winds shifting to WSW at 15 to 25 km/h. Chance of precip 50%."
"Showers early becoming a steady light rain later in the day. Snow may mix in. High 2C. Winds WNW at 10 to 15 km/h. Chance of rain 80%."
What I want to do is to remove the wind part, eg.
Winds NNE at 25 to 40 km/h
NNE winds shifting to WSW at 15 to 25 km/h
Winds WNW at 10 to 15 km/h
If I get the Regular expression syntax right, then I should be able to delete from "Wind" to "km/h" and then have something to delete the direction. At the moment I'm ruining this,
day=replaceAll("{day}", "(SSW )|(SW )|(W )|(NNW )|(NW )|(N )|(NNE )|(NE )|(E )|(Winds )|(shifting )|(at )|[0-9][0-9] to [0-9][0-9]|(km/h)", " ");
which is not optimal. I have been trying to find how to write it, but the syntax doesn't help much. (nor that the notification for nougat doesn't work, so I have to use tts to find what the string contain. I found no good option to find what the variabels contain except the global ones, but tts is faster than to check that every time.)