What is the best way to do this?
Let’s say I have a string that is mixed with letters and numbers,
Srting str = "ha2iwea435";
String str2 = (str Digits);
and I want a string with just the numbers from in between the other letters, or at the end. So my other string would equal the 4th char of str, 2. I suppose I would need to put this in a for loop, and then append a List with the value of str2 so I could assign str2 to 435.
for example,
for(int i = 0; str.length() > i; i++){
str2 = "";
if(str(char_here(i).isNUMBER()) {
for(y = i; str(char_here[y]).isNUMBER(); y++) {
str2 += str.(char_here);
}
}
List1.add(str2);
}
I have no idea what methods and tests to use.
So in the end, I would have a List that equals (“2”, “435”)
Thanks!
You can use a regex to remove the non-digits characters:
If you need each group of numbers in a list you can split on letters and add each group to a list:
And if you want to store the numbers as Strings: