社区
Java SE
帖子详情
还是replaceAll的问题
ppxstar
2002-11-18 06:02:24
replaceAll,是不是不能替用substring取出来的字符串呀??
...全文
33
9
打赏
收藏
还是replaceAll的问题
replaceAll,是不是不能替用substring取出来的字符串呀??
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
abcdhy
2002-11-19
打赏
举报
回复
replaceAll
就是使用一个字符串替换另一个字符串啊
只要你原来是一个字符串就可以用的
public String replaceAll(String regex,String replacement)
函数的返回值就是你要的字符串
signboy
2002-11-19
打赏
举报
回复
嗬嗬,解决问题为首要
ppxstar
2002-11-19
打赏
举报
回复
但是我试着替换的时候根本不能成功
程序没有出问题,编释也成功
但就好象是替换语句没执行一样
我也不想用自己写的replaceAll,因为会增加程序的复杂性
wes109
2002-11-18
打赏
举报
回复
是不是不能替用substring取出来的字符串呀??
取出来的还是不是String??
是!!
So 可以!!!
signboy
2002-11-18
打赏
举报
回复
public static String replaceAll(String str, String old, String news)
{
if(str == null)
return str;
int begin = 0;
int idx = 0;
int len = old.length();
StringBuffer buf = new StringBuffer();
while((idx = str.indexOf(old, begin)) >= 0)
{
buf.append(str.substring(begin, idx));
buf.append(news);
begin = idx + len;
}
return new String(buf.append(str.substring(begin)));
}
javawolf
2002-11-18
打赏
举报
回复
* Replaces each substring of this string that matches the given <a
* href="../util/regex/Pattern.html#sum">regular expression</a> with the
* given replacement.
看样子应该可以适用于所有String,substring也是String啊
ppxstar
2002-11-18
打赏
举报
回复
救命呀!!
ppxstar
2002-11-18
打赏
举报
回复
嗳,人家说java之中无高手,原来是真的
ppxstar
2002-11-18
打赏
举报
回复
有急用,请大伙多帮忙!!
ReplaceAll
ReplaceAll
多文件文本批量替换工具 依赖.net framework2.0
String.prototype.
replaceAll
:适用于String.prototype.
replaceAll
ESnext提案的符合规范的polyfill
string.prototype.
replaceall
用于String.prototype.
replaceAll
的ES Proposal规范填充程序。 如果不可用或不String.prototype.
replaceAll
调用其“ shim”方法对String.prototype.
replaceAll
进行填充。 该软件包实现了接口。 它在ES3支持的环境中工作,并符合。 最常见的用法: const assert = require ( 'assert' ) ; const
replaceAll
= require ( 'string.prototype.
replaceall
' ) ; const str = 'aabc' ; //
replaceAll
and replace are the same, when given a global regex to replace as
replaceall
:替换 JavaScript 字符串中的所有实例
全部替换 替换 JavaScript 字符串中的所有实例。 使用 npm 安装 npm install
replaceall
然后在您的节点应用程序中包含
replaceall
: var
replaceall
= require("
replaceall
"); 使用替换 var result =
replaceall
( "instances of this" , "with this string" , "in this string" ) ; 例子 var original = "hello world goodbye world" ;
replaceall
( "world" , "everyone" , original ) ; // "hello everyone goodbye everyone"
replaceall
( "l" , "z" , original )
Chrome浏览器
replaceAll
报错
问题
Chrome浏览器
replaceAll
报错
问题
JavaScript中实现
replaceAll
方法
我们在Java中可以使用
replaceAll
()方法对字符串进行批量替换,但在JS中
replaceAll
()方法是undefined,JS中只存在replace()方法,因此我们可以自己封装JS中
replaceAll
()方法供我们便捷使用。 一、使用replace()方法进行替换 定义一个字符串: var str = "hello world"; 使用replace()方法将字符串中的字母...
Java SE
62,634
社区成员
307,269
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章