Find and replace Android studio

AndroidAndroid StudioRefactoringRenaming

Android Problem Overview


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?

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.

Android Solutions


Solution 1 - Android

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

Ctrl+Shift+R on Windows and Linux/Ubuntu

Control+Shift+R on macOS (IntelliJ IDEA Classic keymap)

Cmd+Shift+R on macOS (macOS keymap)

ref: source

Solution 2 - Android

On Windows:

Find : Ctrl+F

Find And Replace In Single Class: Ctrl+R

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

on OS X ,it is similar, just replace Ctrl with Command

Solution 3 - Android

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

Solution 4 - Android

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

Solution 5 - Android

Use ctrl+R or cmd+R in OSX

Solution 6 - Android

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

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

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

Solution 7 - Android

The shortcuts are

On Windows : Ctrl+Shift+R

On Mac : Cmd+Shift+R

Solution 8 - Android

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

Solution 9 - Android

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

Solution 10 - Android

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, not three times, and "maintain case" originally present.

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

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.

Solution 11 - Android

This is very simple.

Use Ctrl+R for Windows .

Use Cmd+R for mac.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsirFunkenstineView Question on Stackoverflow
Solution 1 - AndroidKrylezView Answer on Stackoverflow
Solution 2 - AndroidsooglejayView Answer on Stackoverflow
Solution 3 - AndroidZoombieView Answer on Stackoverflow
Solution 4 - AndroidSimonView Answer on Stackoverflow
Solution 5 - AndroidsantaclosView Answer on Stackoverflow
Solution 6 - AndroidPullView Answer on Stackoverflow
Solution 7 - AndroidJGPhilipView Answer on Stackoverflow
Solution 8 - AndroiddazedView Answer on Stackoverflow
Solution 9 - AndroidDineshView Answer on Stackoverflow
Solution 10 - AndroidPete AlvinView Answer on Stackoverflow
Solution 11 - AndroidDeepak guptaView Answer on Stackoverflow