现在我想吧"\"替换为"\\",应该怎么做啊!!replaceall尝试过不行,然后用的新类也不好用,求大神
/**
* 字符串替换函数
* @param from 要替换的字符
* @param to 要替换成的目标字符
* @param source 要替换的字符串
* @return 替换后的字符串
*/
public static String replace(String strSource, String strFrom, String strTo) {
if (strSource == null) {
return null;
}
int i = 0;
if ((i = strSource.indexOf(strFrom, i)) >= 0) {
char[] cSrc = strSource.toCharArray();
char[] cTo = strTo.toCharArray();
int len = strFrom.length();
StringBuffer buf = new StringBuffer(cSrc.length);
buf.append(cSrc, 0, i).append(cTo);
i += len;
int j = i;
while ((i = strSource.indexOf(strFrom, i)) > 0) {
buf.append(cSrc, j, i - j).append(cTo);
i += len;
j = i;
}
buf.append(cSrc, j, cSrc.length - j);
return buf.toString();
}
return strSource;
}java
/**
* 字符串替换函数
* @param from 要替换的字符
* @param to 要替换成的目标字符
* @param source 要替换的字符串
* @return 替换后的字符串
*/
public static String replace(String strSource, String strFrom, String strTo) {
if (strSource == null) {
return null;
}
int i = 0;
if ((i = strSource.indexOf(strFrom, i)) >= 0) {
char[] cSrc = strSource.toCharArray();
char[] cTo = strTo.toCharArray();
int len = strFrom.length();
StringBuffer buf = new StringBuffer(cSrc.length);
buf.append(cSrc, 0, i).append(cTo);
i += len;
int j = i;
while ((i = strSource.indexOf(strFrom, i)) > 0) {
buf.append(cSrc, j, i - j).append(cTo);
i += len;
j = i;
}
buf.append(cSrc, j, cSrc.length - j);
return buf.toString();
}
return strSource;
}java
解决方案 »
- java 按月份生成文件
- 一个最起码有50%的人不知道的问题,JAVA基础题目,请精通JAVA的大侠回答下
- 急急急 javaSE程序中使用proxool都需要哪些jar文件
- java里有数据集的概念吗 是否和C#有相似之处 !@@
- 在两个JTextField中输入相同的情况下,为何它们的.getText()不相同呢?
- 高手帮忙解决下数据库的问题
- 关于Hashtable的问题.请高人帮忙.
- .class为扩展名是什么意思?本人从没接触过java,请多多指教。
- 为什么是最小化哦显示????
- 如何定义方法,使其为deprecated的方法
- 怎么理解监听器的注册?
- 求助:怎么把工具栏按钮在界面左边竖直排列?
replaceAll("\\\\","\\\\\\\\");