Java 字符串转换:将 [["SCJY","SQ"]] 转换为 'SCJY','SQ'
可以使用正则表达式来去除字符串中的多余字符,将其转换为所需的格式。
以下是一个示例代码:
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/qAsZ 著作权归作者所有。请勿转载和采集!