如何将从数据库里面读到的'SZ,DG,HK'转化为'SZ','DG','HK' 在线等谢谢 注明:我们公司的数据库不支持split函数(如果支持这个函数就好办拉) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String test="'DG,HK,GZ'";String result = test.replaceAll(",","','");System.out.println(result);行吗? 楼上的,这样可是可以,问题就是我的test这个变量的内容是不确定的呀,如果是test="SZ"那怎么控制呢?又如果test="sz,GF,UK,VF,BJ"那又怎么处理呢?不过都谢谢你 Java中有Split函数用StringTokenizer也可以 class Cls{ public static void main(String[] args){ String test="DG,HK,GZ"; String result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" ); System.out.println(result); test = "SZ,GF,UK,VF,BJ"; result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" ); System.out.println(result); test = "SJ"; result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" ); System.out.println(result); }} 跪求! 急急急!!!本人只有这点分,谅解一下。。。 怎么可以像淘宝店铺那样做短网址功能 把网站的首页转换成Bitmap JS中获取eWebEditor.jsp的内容? BoneCP: 比 C3P0 性能还要好的 Java 连接池 空指向异常,急求高手!!! 动态生成表单的问题 为什么在Jbuilder2006中为JSP页面设背景用background就报错,但又可以运行? 近期看到许多朋友在问数据库连接池的问题,所以特地总结了一下. 请教JSP如何实现字体闪烁? 使用JDBC写入汉字时遇到问题,请大家帮忙解决. 在oracle里面如何查询某年的数据?
String result = test.replaceAll(",","','");
System.out.println(result);行吗?
test="SZ"那怎么控制呢?
又如果test="sz,GF,UK,VF,BJ"那又怎么处理呢?不过都谢谢你
class Cls{
public static void main(String[] args){
String test="DG,HK,GZ";
String result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" );
System.out.println(result);
test = "SZ,GF,UK,VF,BJ";
result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" );
System.out.println(result);
test = "SJ";
result = test.replaceAll( "([a-zA-Z]{2})(,?)", "'" + "$1" + "'$2" );
System.out.println(result);
}
}