Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java string: how do I get the value of X, Y, and Z from a string "vt X,Y,Z"

Tags:

java

string

how do I get the value of X, Y, and Z from a string "vt X,Y,Z"

like image 651
William Avatar asked Jan 21 '26 13:01

William


1 Answers

As long as the format stays simple like that, I'd use

String s = "vt X, Y, Z";
String[] values = s.split("[ ,]+");
String x = values[1];
String y = values[2];
String z = values[3];

If the format has more flexibility, you'll want to look into using either a regular expression (the Pattern class) or creating a parser for it using something like ANTLR

like image 179
Scott Stanchfield Avatar answered Jan 24 '26 06:01

Scott Stanchfield