查找和替换 Android Studio

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20249274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:31:23  来源:igfitidea点击:

Find and replace Android studio

androidandroid-studiorefactoringrenaming

提问by sirFunkenstine

Is there a way to find and replace all occurrences of a word in an entire project( not just a single class using refactor -> rename) and also maintain case, either in android studio or using a command line script?

有没有办法在整个项目中查找和替换所有出现的单词(不仅仅是使用重构 -> 重命名的单个类)并且还可以在 android studio 中或使用命令行脚本维护大小写?

For example, Supplier has to go to Merchant, supplier -> merchant, SUPPLIER -> MERCHANT. My boss wants me to change all instances of supplier with merchant for a project im working on. Ive been doing it for about an hour and i know im wasting my time. Let me know of any time saving suggestions.

例如,供应商必须转到商家,供应商 -> 商家,供应商 -> MERCHANT。我的老板希望我为我正在进行的项目更改供应商与商家的所有实例。我已经做了大约一个小时,我知道我在浪费时间。让我知道任何节省时间的建议。

回答by Krylez

I think the shortcut that you're looking for is:

我认为您正在寻找的快捷方式是:

Ctrl+Shift+Ron Windows and Linux/Ubuntu

Ctrl+ Shift+R在Windows和Linux / Ubuntu的

Cmd+Shift+Ron Mac OS X

Cmd+ Shift+R在 Mac OS X 上

ref: source

参考:来源

回答by sooglejay

On Windows:

Windows 上

Find : Ctrl+F

查找:Ctrl+F

Find And Replace In Single Class: Ctrl+R

在单个类中查找和替换:Ctrl+R

Find And Replace In Whole Project: Ctrl+Shift+R

查找并替换整个项目:Ctrl+ Shift+R

on OS X,it is similar, just replace Ctrlwith Command

OS X 上,它是相似的,只需替换CtrlCommand

回答by Zoombie

In Android studio, Edit -- > Find --> Replace in path, this will check in whole project including comments and code.

在 Android Studio 中,Edit --> Find --> Replace in path,这将检查整个项目,包括注释和代码。

回答by Pull

If you use refactor->rename for the name of the file, everywhere the file is used in your project the refactor will replace it.

如果您使用 refactor->rename 作为文件名,那么在您的项目中使用该文件的任何地方,重构都会替换它。

I have already rename variables, xml file, java file, multiple drawable and after the operation I could build directly without error.

我已经重命名了变量,xml文件,java文件,多个drawable,操作后我可以直接构建而不会出错。

Do a back-up of your project and try to see if it work for you.

备份您的项目并尝试查看它是否适合您。

回答by Simon

Press Ctrl+Rto find and replace codes in the class where you are...

Ctrl+R查找和替换您所在班级中的代码...

回答by user3245882

Use ctrl+Ror cmd+Rin OSX

在 OSX 中使用ctrl+Rcmd+R

回答by JGPhilip

The shortcuts are

捷径是

On Windows: Ctrl+Shift+R

在Windows上Ctrl+ Shift+R

On Mac: Cmd+Shift+R

在MacCmd+ Shift+R

回答by Dinesh

ctrl + H..... its give option to replace word from class.

ctrl + H..... 它给出了替换类中单词的选项。

回答by Pete Alvin

I think the previous answers missed the most important (non-trivial) aspect of the OP's question, i.e., how to perform the search/replace in a "time saving" manner, meaning once, notthree times, and "maintain case" originally present.

我认为以前的答案错过了 OP 问题最重要(非平凡)的方面,即如何以“节省时间”的方式执行搜索/替换,意思是一次而不是三次,并且最初是“维护案例”展示。

On the pane, check "[X] Preserve Case" before clicking the Replace All button

在窗格中,在单击“全部替换”按钮之前选中“ [X] Preserve Case

This performs a case-aware "smart" replacement in one pass:

这将在一次传递中执行案例感知“智能”替换:

apple -> orange
Apple -> Orange
APPLE -> ORANGE

Also, for peace of mind, don't forget to check the code into the VCS before performing sweeping project-wide replacements.

此外,为了安心,在执行全面的项目范围替换之前,不要忘记将代码签入 VCS。

回答by dazed

Try using: Edit -> Find -> Replace in path...

尝试使用:编辑 -> 查找 -> 在路径中替换...