社区
Java SE
帖子详情
初学者问题:如何实现字符串的替换
zl198183
2004-11-11 01:12:28
class MyUtil {
String replaceString
(String original, String replacement){}
}
...全文
144
7
打赏
收藏
初学者问题:如何实现字符串的替换
class MyUtil { String replaceString (String original, String replacement){} }
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zl198183
2004-11-11
打赏
举报
回复
如果不用已有的REPLACE()方法,还有别的方法吗?
replaceall()方法是如何具体实现的??
caiyi0903
2004-11-11
打赏
举报
回复
一百遍啊一百遍!!
御南
2004-11-11
打赏
举报
回复
用JTextArea的replaceRange(textString,int start,int end)方法
classjava
2004-11-11
打赏
举报
回复
public class Test
{
public static void main(String[] args)
{
String s="csdn.net";
String sChange=s.replaceAll("csdn","classjava");
System.out.println(sChange);
}
}
这是String类的一个method
String replaceAll(String s1,string s2)
treeroot
2004-11-11
打赏
举报
回复
用String类的replaceAll()方法
bestdelphier
2004-11-11
打赏
举报
回复
/**
* 将source字符串中的replaceWith字符串替换成replaceTo字符串
* @param source String 源字符串
* @param replaceWith String源字符串中待替换的字串
* @param repalceTo String源字符串中字串欲替换成的字串
* @return java.lang.String 替换之后的字符串
*/
public static String replaceString(String source, String replaceWith, String replaceTo)
{
StringBuffer sb=new StringBuffer();
int iLength=replaceWith.length();
int iLastPos=0,iFindPos=0;
iFindPos=source.indexOf(replaceWith,0);
while (iFindPos!=-1){
sb.append(source.substring(iLastPos,iFindPos));
sb.append(replaceTo);
iLastPos=iFindPos+iLength;
iFindPos=source.indexOf(replaceWith,iLastPos);
}
sb.append(source.substring(iLastPos,source.length()));
return sb.toString();
}
treeroot
2004-11-11
打赏
举报
回复
String类就有这个方法
Bootstrap入门适合
初学者
从基础讲起,既有理论讲解也有代码实战,非常适合
初学者
入门学习。 课程内容包括: 1. bootstrap概述 2. bootstrap全局样式 3. bootstrap插件 4. bootstrap...
c++基础(二):
字符串
替换
及文件路径截取文件名
继续昨天未写完的...我是
初学者
,如果觉得太简单,勿喷,如果有什么错误之处,请指出,多谢~! 今天整理了写的根据文件路径截取文件名相关代码,主要包含
替换
路径中... *
字符串
替换
将str中所有的src
替换
为dst */...
Java中的
字符串
替换
在Java中,String 类提供了 3 种
字符串
替换
方法,分别是 replace()、replaceFirst() 和 replaceAll(),下面我们就来详细看一下三种的用法!下面这套视频专门为零基础而制,适合准备入行Java开发的零基础,视频中穿插...
如何在JavaScript中
实现
字符串
模板
替换
?
如何在JavaScript中
实现
字符串
模板
替换
?
python
初学者
指南:繁杂的
字符串
python中
字符串
的各种方法(附示例)
Java SE
62,614
社区成员
307,326
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章