We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,820 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Reading Substring from a string

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...

4
Contributors
4
Replies
2 Days
Discussion Span
4 Years Ago
Last Updated
5
Views
k88joshi
Newbie Poster
24 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

s/(\w+)\.world/$1.earth/g;

KevinADC
Posting Shark
921 posts since Mar 2006
Reputation Points: 246
Solved Threads: 67
Skill Endorsements: 0

exactly. And if you have to read in multiple files, I would suggest you use:

undef ($|);

which will suck the entire file into a variable for replacement.

mitchems
Posting Whiz in Training
295 posts since Feb 2009
Reputation Points: 26
Solved Threads: 38
Skill Endorsements: 0

....

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 216
Skill Endorsements: 27

Alright, I know I'm not supposed to back post. But I realized my suggestion was incorrect (sorry, still getting the hang of this). I meant $/ not $|.

undef($/);

which will set the end of record to end of file. Then you can suck the entire file into a variable for replacement.

mitchems
Posting Whiz in Training
295 posts since Feb 2009
Reputation Points: 26
Solved Threads: 38
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.3278 seconds using 2.69MB