How to I extract the following substring from a string in Java.
string var=fill x [0,4,4,4] #1000ff
I want to extract only the fill x
(with whitespaces).
Can anyone help me out?
尝试这个:
String result = var.substring(0,var.indexOf("["));
String subString = var.substring(begin, end + 1);
// begin and end is the integer index of var string where you want to get
in your example, it should be:
String subString = var.substring(0, var.indexOf("[")); // if include white space
String subString = var.substring(0, var.indexOf("x") + 1); // if not include white space
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.