System.out.println(
Integer.parseInt(
Arrays.toString(
text.getText().replaceAll("--","").split("x")
)
)
)
How do I get to split in two places?
Question
I would like to get something to work, a splitting in two places.
System.out.println( Integer.parseInt(text.getText().split("--")[1]
.substring((text.getText().split("--")[1]).split("x")[0])));
does not work. If I type --400x55
how do I get it to print "400 , 55".
I want it to be changeable, so if the user types some different dimensions, it will use those. So how would I do this?
Solution
OTHER TIPS
Try:
String[] tokens = text.split("x");
System.out.println(tokens[0].split("-")[2] + " , " + tokens[1]); // tokenize by -
or
String[] tokens = text.split("x");
System.out.println(tokens[0].split("--")[1] + " , " + tokens[1]); // tokenize by --
Hope this helps.
String text="--400x55";
System.out.println(text.split("--")[1]); // gives you 400x55
System.out.println(text.split("--")[1].split("x")[0]); // gives you 400
System.out.println(text.split("--")[1].split("x")[1]); // gives you 55
use Regular expression to split
"--400x55".split(/\D/)
it gives you ["","","400","55"]
use the above array according to your need
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow