Hello,

I am working on something where i need to search and replace many variable names of a program.

For example,
I have a class Hello and its public variable is world, but the variable world has been changed to earth so now in the program i need to go and replace the world variable with earth. this is just one example but there are many different

variables to be replaced.

Hello.world replace by 
Hello.earth

variables to be replaced. code ..... Hello.world replace by Hello.earth code ....

so far i have a 2D array with old variable name and new variable name

but i am not able to find the strings such as world since it is in a single word Hellol.world

Please help on how to look for world in AnyClassName.old_VariableName and replace it by AnyClassName.new_VariableName

Thank You...

What the fuck? You asked this in the C++ forum and didn't even need to write it in C++, and got answers. Why are you asking it in the Java forum?

Check the API for the String class. It has a replace method.
Also if you search this forum you will find examples on how to read and writes files.

So read the file line by line.
For each line use the replace method and save the result (the modified line) into a collection (check the API for ArrayList).
After you are finished with the file, write all the lines that are inside the ArrayList back to the file

Hello,

For example,
I have a class Hello and its public variable is world, but the variable world has been changed to earth so now in the program i need to go and replace the world variable with earth. this is just one example but there are many different

variables to be replaced.

if your ide supports it: find-replace.
or, there are some ide's that give the option to 'refactor'

if you don't know your ide well enough, or your ide doesn't support it, check every file for a reference to the variable 'world' and update it manually.

it doesn't really need the next Einstein to figure that much out

It is not a code .. i want to use it for a different purpose and there are 100s of memebers not only .world

This article has been dead for over six months. Start a new discussion instead.