开发者社区> 问答> 正文

如何用replaceAll() 方法来进行Java的字符串替换呢?

已解决

如何用replaceAll() 方法来进行Java的字符串替换呢?

展开
收起
游客3gzok77e677xw 2022-04-03 10:21:20 623 0
1 条回答
写回答
取消 提交回答
  • 推荐回答
    replaceAll() 方法用于将目标字符串中匹配某正则表达式的所有子字符串替换成新的字符串,其语法形式如下:
    字符串.replaceAll(String regex, String replacement)
    其中,regex 表示正则表达式,replacement 表示用于替换的字符串。例如:
    String words = "hello java,hello php";
    String newStr = words.replaceAll("hello","你好 ");
    System.out.println(newStr);    // 输出:你好 java,你好 php
    
    2022-04-03 13:06:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载