I have a java file which I got from android, this has some hard coded values in it. Basically we have a file which creates an object of type country and adds it to a list.
I wish to attain the same functionality but I am not sure of the reg-ex required to find and replace the file contents. Basically this is how one of the lines in it looks like...
countries.add(new Country("af", "Afghanistan", 93));
And this is what I wan't it to look like
[countries addObject:[[Country alloc] initWithArray:@[@"af",@"Afghanistan",@"93"]];
Do you think regex can be used for such extensive case..? Or will I have to manually do this for every entry..?
You can do a literal search and capture groups like this and replace them.
Regex: countries\\.add\\(new Country\\("([az]+)", "(.*)", (\\d+)\\)\\);
Replacement to do: [countries addObject:[[Country alloc] initWithArray:@[@"$1",@"$2",@"$3"]];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.