我有以下字符串“Welcome to Java”,我需要提取引号内的字符,是否有内置方法可以做到这一点?就像 trim
方法删除字符串前后的空格一样。
请注意,“是字符串的一部分。
最佳答案
您可以使用 apache commons lang 中的 StringUtils,但需要先转义引号。
这是示例。
import org.apache.commons.lang3.StringUtils;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String str = "\"Welcome to Java\"";
String res = StringUtils.substringBetween(str, "\"", "\"");
System.out.println(res);
}
}
关于java - 删除首尾字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58759057/