例如,我有如下所示的字符串:
<http://www.w3.org/2000/01/rdf-schema#label> "Telecommunications law"@en <http://en.wikipedia.org/wiki/> 提取子字符串的最简单方法是什么:
Telecommunication law请注意,子字符串包含一个空格。
发布于 2012-05-04 17:41:46
你可以使用Pattern和Matcher:
Pattern p = Pattern.compile("\".*\"");
Matcher m = p.matcher(s);
if(m.find()){
String resultString = m.group();
}在你的例子中,resultString将包含“电信法”,如果你不想保留双引号,你可以删掉它们。
发布于 2012-05-04 17:28:42
在"上选择字符串,然后选择返回数组中的第二个元素:
String tokens[] = yourString.split("\"");
// tokens[1] will contain Telecommunications law发布于 2012-05-04 17:36:34
“提取字符串”是什么意思?
通过以下方式获取字符串的第一个匹配项:
int index = string.indexOf("Telecommunications law");获取第一个括号和第二个括号之间内容的最有效方法是:
final String test="http://www.w3.org/2000/01/rdf-schema#label \"Telecommunications law\"@en http://en.wikipedia.org/wiki/";
final int firstIndex=test.indexOf('\"');
final int lastIndex=test.indexOf('\"',firstIndex+1);
final String result=test.substring(firstIndex+1,lastIndex);
System.out.println(result);https://stackoverflow.com/questions/10446177
复制相似问题