社区
Java SE
帖子详情
初学者问题:如何实现字符串的替换
zl198183
2004-11-11 01:12:28
class MyUtil {
String replaceString
(String original, String replacement){}
}
...全文
255
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类就有这个方法
替换
空格
链接:https://www.nowcoder.com/questionTerminal/4060ac7e3e404ad1a894ef3e17650423?orderByHotValue=1 来源:牛客网 [编程题]
替换
空格 热度指数:377410 时间限制:1秒 空间限制:32768K 请
实现
一个函数,将一个
字符串
中的空格
替换
成“%20”。 例如,当
字符串
为W
字符串
习题(下)
大家好,我是Python领域的博主。 如果你是编程爱好者可以小编一起学习,在这里我每天都会发Python的基础知识,以及相关的代码。 如果文章有什么错误的地方,请不吝赐教。 觉得博主文章写的还错的话,请三连支持一下博主哦 我一直坚信一句话:我相信努力一定会有回报,这个回报可能很慢,但请相信,只要你坚持下去一定会更好的。 系列专栏: Python小游戏及登录系统_ 01-try-except异常处理 02-continue与break的区别 03-人机交互讲解 04-
字符串
...
剑指offer day3
字符串
(简单)
day3题目:剑指 Offer 05.
替换
空格、剑指 Offer 58 - II. 左旋转
字符串
知识点:
字符串
,难度为简单、简单
【剑指Offer】
字符串
今天的题太简单了,不用3、4行代码就写好了。。。晒一下代码吧,感觉没什么好讲的,第一题直接遍历然后
替换
,第二题直接想象成循环队列就好了。
替换
空格 请
实现
一个函数,把
字符串
s 中的每个空格
替换
成"%20"。 示例 1: 输入:s = "We are happy." 输出:"We%20are%20happy." 限制: 0 <= s 的长度 <= 10000 class Solution { public: string replaceSpace(string s) {
【剑指Offer】
替换
空格&&重建二叉树
【剑指Offer】
替换
空格 题目描述: 将一个
字符串
中的每个空格
替换
成“%20” 例如: 输入:"We Are Happy" 输出:"We%20Are%20Happy" 思路分析: 直接用replace()方法 逐个遍历进行
替换
代码
实现
: public class Solution { public String replaceSpace (String s) { // 方法一:正则匹配 // return s.replaceAll("\\s", "%20
Java SE
62,620
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章