on  it road.com

Java String replaceFirst() 示例

public class StringExample 
{
    public static void main(String[] args) 
    {
        String str = "hello world,hello java,hello onitroad";

        // 将第1个hello替换为 Hello
        String newStr = str.replaceFirst("hello", "Hello");

        // 将第一个r替换为R
        String regexResult = str.replaceFirst("[r]", "R");

        System.out.println(newStr);
        System.out.println(regexResult);
    }
}
Java String replaceFirst() 方法

Java String replaceFirst() 方法用于替换第1次匹配的子字符串。

日期:2020-09-17 00:10:10 来源:oir作者:oir