已知:yi er san si wu liu qi ba jiu 分别对应123456789,
对一段只含有这几种字符串的字符串进行转换,用java编程解答
yi er san si wu liu qi ba jiu 分别对应123456789,对一段只含有这几种字符串的字符串进行转换
答案:2 悬赏:20 手机版
解决时间 2021-03-20 01:27
- 提问者网友:戎马万世
- 2021-03-19 14:53
最佳答案
- 五星知识达人网友:行雁书
- 2021-03-19 16:29
// 字符串替换
public static String Replace(String source,String oldString,String newString){
if (source == null) {
return null;
}
StringBuffer output = new StringBuffer();
int lengOfsource = source.length();
int lengOfold = oldString.length();
int posStart;
int pos;
for (posStart = 0;(pos = source.indexOf(oldString, posStart))>=0;posStart=pos+lengOfold){
output.append(source.substring(posStart,pos));
output.append(newString);
}
if (posStart < lengOfsource) {
output.append(source.substring(posStart));
}
return output.toString();
}
public static String Replace(String source,String oldString,String newString){
if (source == null) {
return null;
}
StringBuffer output = new StringBuffer();
int lengOfsource = source.length();
int lengOfold = oldString.length();
int posStart;
int pos;
for (posStart = 0;(pos = source.indexOf(oldString, posStart))>=0;posStart=pos+lengOfold){
output.append(source.substring(posStart,pos));
output.append(newString);
}
if (posStart < lengOfsource) {
output.append(source.substring(posStart));
}
return output.toString();
}
全部回答
- 1楼网友:等灯
- 2021-03-19 17:31
s,b
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯