如何在Java中替换第一次出现的字符串 [英] How to replace first occurrence of string in Java
本文介绍了如何在Java中替换第一次出现的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在下面替换第一次出现的String。
I want to replace first occurrence of String in the following.
String test = "see Comments, this is for some test, help us"
**如果test包含如下输入,则不应替换
**If test contains the input as follows it should not replace
- 查看评论,(最后有空格)
- 查看评论,
- 见评论**
我想得到如下输出,
Output: this is for some test, help us
提前致谢,
推荐答案
您可以使用 replaceFirst(String regex,字符串替换)
String的方法。
You can use replaceFirst(String regex, String replacement)
method of String.
这篇关于如何在Java中替换第一次出现的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文