Here is my string with 3 integers and I want to store it in 3 integer variables but I am unable to find an answer.
string orders = "Total orders are 2222 open orders are 1233 closed are 222";
This is what I want to do.
int total = 2222;
int close = 222;
int open = 1233;
Try using regular expressions (to extract patterns) and Linq (to organize them into int[]):
string orders = "Total orders are 2222 open orders are 1233 closed are 222";
int[] result = Regex
.Matches(orders, "[0-9]+")
.OfType<Match>()
.Select(match => int.Parse(match.Value))
.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With