Finding a repeating pattern in a given string
-
13-04-2021 - |
Question
I have a networkstream (using C#/VB.NET). while on reading values coming like this:
&% 68 kg K A&% 23 kg K A&% 174 kg K A &% 68 kg
&% 34 kg K A&% 2334 kg K A&% 68 kg K A &% 68 kg K A
&% 2348 kg K A&% 78 kg K A&% 28 kg K A&% 68 kg
The numerical(weight) value will be continuously varying.
Every time i am reading the starting of the stream differs. But the pattern remains the same. How to split that into '&% 78 kg K A' which represents one set.
How to extract the weight value from this stream using Regex or any other methods?
Solution
You may try.
string str="&% 68 kg K A&% 23 kg K A&% 174 kg";
string []ar=Regex.Split(str,@"[^0-9]").Where(p=> p!=string.Empty).ToArray();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow