[英]How to extract substring from a griven string in java
How to I extract the following substring from a string in Java. 如何从Java中的字符串中提取以下子字符串。
string var=fill x [0,4,4,4] #1000ff
I want to extract only the fill x
(with whitespaces). 我想只提取
fill x
(用空格)。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.