3 Mayıs 2023 Çarşamba

Matcher.replaceAll metodu

Giriş
İmzası şöyle
String replaceAll(Function<MatchResult,String>)
Örnek
Şöyle yaparız.
var str = "Anyone born between 1981 and 1996 is considered a candidate";

var r = new Random();

var str2 = Pattern.compile("[0-9]+").matcher(str)
        .replaceAll(m -> String.valueOf(Integer.parseInt(m.group()) + r.nextInt(5)));

System.out.println(str2);
// Anyone born between 1983 and 1999 is considered a candidate

Hiç yorum yok:

Yorum Gönder