Java中怎么转换字符串SCJYSQ为SCJYSQ
可以使用正则表达式来去除字符串中的多余字符,将其转换为所需的格式。
以下是一个示例代码:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String str = "[[\"SCJY\",\"SQ\"]]";
String pattern = "\\[\\[\"(.*)\",\"(.*)\"\\]\\]";
Pattern regex = Pattern.compile(pattern);
Matcher matcher = regex.matcher(str);
if (matcher.find()) {
String result = matcher.group(1) + "\",\"" + matcher.group(2);
System.out.println(result);
}
}
}
输出结果为:"SCJY","SQ
原文地址: https://www.cveoy.top/t/topic/iUtj 著作权归作者所有。请勿转载和采集!