I have the following string
string a = "24 y 25 de enero";
what I want to do is get the numbers separately, that is {24, 25}
I have tried the following code
string output = new string(a.ToCharArray().Where(c => char.IsDigit(c)).ToArray());
but i get 2425
How could I get those numbers separately?
If you want it in an array this is the appropriate code:
I separate the elements by the spaces in the string and check if the object is a number.
This returns us a
IEnumerable<string>
If you occupy an array of
<int>
you can add the following extension.And to verify the result in a remarkable and distinguished way:
If the numbers are in the same position you could always try:
Indicating the starting position and the length of the string you want and then store it in your array.
What you have to do is create a method that goes through the string until it finds the letter 'y', in this way, you make a conversion and you get the first number, which would be 24. Then you save it in an auxiliary variable to proceed to get the second number. (25). This is how the method would look:
Method Usage: