Java字符串类replaceAll方法丢失 [英] Java String class replaceAll method missing

查看:57
本文介绍了Java字符串类replaceAll方法丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在遇到一个很奇怪的问题,String对象中缺少replaceAll方法.

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

JDK版本:1.8.0
Android Studio版本:3.1.3
Kotlin版本:1.2

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

它尚未被删除,所以这里发生了什么??

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

推荐答案

您只需

You can do this with just replace in Kotlin:

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

请注意,上述调用将替换文字字符串,如果您需要Regex作为第一个参数,则可以执行以下任一操作:

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"

这篇关于Java字符串类replaceAll方法丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆