I have an string like this:
"ADDRESS 47, 0, 2, 0, 1, 0"
or
"ADDRESS 47, 100, 2, 5, 1, 0"".
And now I want to filter the third Number(for example the 2).
I am prorgamming in C#.
Can sameone help me?
I have an string like this:
"ADDRESS 47, 0, 2, 0, 1, 0"
or
"ADDRESS 47, 100, 2, 5, 1, 0"".
And now I want to filter the third Number(for example the 2).
I am prorgamming in C#.
Can sameone help me?
This code might work:
string input = "ADDRESS 47, 0, 2, 0, 1, 0";
string numbersOnly = input.Substring("ADDRESS ".Length);
string[] parts = numbersOnly.Split(", ");
string result = parts[2];
First, you create a substring that doesn't contain the prefix (not necessary if you are not interested in the first number). After that, you split your string into parts. Chose the part with index 2 to get the third number.
If you want to do calculations with the number, you have to convert it into an integer. Replace the last line with
int result = int.Parse(parts[2]);
Online demo: https://dotnetfiddle.net/txb25A