1.Java replaceFirst简介
该方法替换与该正则表达式匹配的给定字符串的第一个子字符串。
2.Java replaceFirst语法
public Str replaceFirst(String rgex, String replacement)
参数:
rgex:给定字符串需要匹配的正则表达式。
替换:替换正则表达式的字符串。
3.Java replaceFirst示例
public class Test { public static void main(String args[]) { String Str = new String("hello mikechen,my name is mike chen, too。"); System.out.print("返回值 :" ); System.out.println(Str.replaceFirst("mikechen", "ada" )); } }
执行结果:
返回值 :hello ada,my name is mike chen, too。