日期:2014-05-20  浏览次数:20674 次

JAVA String 如何去掉指定字符
如题
有字符串a,
想去掉a中的c,
先用indexOf(),得到a中c的位置,
再用substring()分别获取c字符左边的字符串和右边的字符串.
再将两个字符串连起来吗?
这样效率比较低啊.

int   location   =a.indexOf(c),
String   left=a.substring(0,location   );
String   right   =   expInPutCode.substring(location   +1,a.length());
a=left+right;


求更好的办法
求更好的办法
求更好的办法
求更好的办法
求更好的办法
求更好的办法
求更好的办法
求更好的办法
求更好的办法



------解决方案--------------------
replaceAll()
------解决方案--------------------
public class Test
{
public static void main(String[] args)
{
String s= "abcdabcdabcd ";
System.out.println(s);
System.out.println(s.replaceAll( "a ", " "));
}
}