1
I have the following function:
string str = "1 2 3 4 5"; //string para separar
string[] ArrayValor = str.Split(" ");
//nesse caso o array seria {"1","2","3","4","5"}
but wanted something more generic, for example, if the user put "1-2-3-4-5", he also wanted the array to return {"1", "2", "3", "4", "5"}
in short, I just want the numbers of a string, no matter what’s between them.
Use the function split -
str.Split(" ")
– Pedro Camara Junior
more I needed to figure out the spliter, like if the string was "1-2-3-4-5" assign to the spliter the "-"
– Jackson José Gomes Do Valle
Your question is not very clear as to what you want, try to make it clearer that it will be easier to find some help. :)
– Pedro Camara Junior
Now, what can there be between the numbers? Are they always the same characters? Can they be different characters in the same string?
– Pedro Camara Junior
may be different characters, I will try to make the question clearer
– Jackson José Gomes Do Valle
Do you want to separate by any character that is between the numbers? For example, if the string is
"2+5-4a8s4"
, you want to get an array only with the numbers?– Pedro Camara Junior
no, actually the string will only have numbers (some with comma) and the spliter (which I have no control, sometimes it is a space, sometimes it is a dash and so on)
– Jackson José Gomes Do Valle
I closed because the accepted answer does not match what the question is asking. If the question becomes clearer it is possible to reopen.
– Maniero