Java String class replaceAll method missing

daka :

I'm having a very weird issue right now, the replaceAll method is missing from the String object.

JDK version: 1.8.0
Android Studio version: 3.1.3
Kotlin version: 1.2

enter image description here

It hasn't been removed, so whats going on here??

zsmb13 :

You can do this with just replace in Kotlin:

"foo and foo".replace("foo", "bar") // "bar and bar"

Note that the call above replaces the literal strings, if you need a Regex as the first parameter you can do either of the following:

"foo and bar".replace("[abcd]".toRegex(), "x") // "foo xnx xxr"
"foo and bar".replace(Regex("[abcd]"), "x")    // "foo xnx xxr"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=35716&siteId=1