android-studio - 在 Android Studio 中查找并用间隙/通配符替换单词

标签 android-studio find-replace

有没有办法找到具有一个或多个间隙的特定代码?比如我要替换

.setImageResource(R.drawable.*)

.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.*))

这里*表示名称将保持以前的样子。

最佳答案

是的,这是可能的。单击Ctrl+Shift+R。您将看到类似这样的内容:

enter image description here

选择Regex,然后在第一个字段中粘贴:

.setImageResource\(R.drawable.(.*)\)

第二个:

.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.$1))

此替换基于正则表达式。在第一个语句中,您在 () 括号中的 R.drawable 之后设置组。该组可以通过使用 $1 在第二个语句中使用。 1 是组的编号。 0 是完整的正则表达式,下一组从 1 开始集成。

结果:

.setImageResource(R.drawable.something1)
.setImageResource(R.drawable.something2)

已更改为

.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.something1))
.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.something2))

Here您可以阅读有关 IntelliJ IDEA 中使用正则表达式查找和替换的更多信息

关于android-studio - 在 Android Studio 中查找并用间隙/通配符替换单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63651257/

相关文章:

android-studio - Android Studio : Create a second Windows window

安卓工作室 : Android Manifest doesn't exists or has incorrect root tag

vim - 在Vim中,如何有效地搜索 “and ”并将其替换为普通的双引号“

regex - Visual Studio Code 查找/替换 - 使用名称保存

android - 找不到参数 [com.android.volley.tests] 的方法 testPackageName()

java - 使图像文件夹在项目中可用

Android Studio 数据库检查器始终将数据库显示为 "closed"

python - 在 pandas 数据框中查找并替换 "-inf"

SQL Server : find and replace part of a specific part of string that appears more than once in a string