|
Answer» Hi,
I currenly created a GUI and I wish to use DOS command to replace a source file's string. For example, I have a source file(.cpp) with a string "hello", I wish to use DOS command to replace the string "hello" to "bye" in that source file.
I reseached and tried many method but still not working. I tried the "munge" function but it is not working. I also tried perl but the source file string doesn't change.
Help....I really really need this urgently.
Regards,
AdrianAny decent text editor can do this. Is there some special reason you want to do it the hard way? Hi,
Thanks for reply, I am doing this because I am trying to get value from another C++ file and automatically change the value of my current PROGRAM.
For example, in my current program I have a code line:
_LIT(KElementId, "StandbyScreen");
So, how can I change it to:
_LIT(KElementId, "Work");
I wish to change the string using DOS code. Any help? I need this urgently.
ThanksHi,
The perl method is working. The replacing method is as below:
perl -pi -i.bak -E "s/searchterm/replaceterm/" *.cpp
I was able to change the string "hello" to "bye" using example below:
perl -pi -i.bak -e "s/hello/bye/" helloworld.cpp
However, I encountered another problem when my string is "c:\\media\\image\\wallpaper"
Since there is slash in the string, the perl code can't recognize and replace the term. Any help?? Urgent
Thanks
I still struggling with the problem....any help pls......
thanks in advancehttp://www.unix.org.ua/orelly/perl/learn/ch07_04.htm
If you are looking for a string with a regular expression that contains slash characters (/), you must precede each slash with a backslash (\ ). For example, you can look for a string that begins with /usr/etc like this:
$path = ; # read a pathname (from "find" perhaps?) if ($path =~ /^\/usr\/etc/) { # begins with /usr/etc... }
As you can see, the backslash-slash combination makes it look like there are little valleys between the text pieces. Doing this for a lot of slash characters can get cumbersome, so Perl allows you to specify a DIFFERENT delimiter character. Simply precede any nonalphanumeric, nonwhitespace character (your selected delimiter) - with an m, then list your PATTERN followed by another identical delimiter character, as in:
/^\/usr\/etc/ # using standard slash delimiter [emailprotected]^/usr/[emailprotected] # using @ for a delimiter m#^/usr/etc# # using # for a delimiter (my favorite)
- If the delimiter happens to be the left character of a left-right pair (parentheses, braces, angle bracket, or square bracket), the closing delimiter is the corresponding right of the same pair. But otherwise, the characters are the same for begin and end.
Hi,
Thanks for your guidance. However, I still face problem on replacing the following line:
I wish to replace the string "http://mms.starhubgee.com.sg:8002/" with "http://mms.singtel.com:10021/mmsc"
Here is what I did: perl -pi -i.bak -e "s/m#^http://mms.starhubgee.com.sg:8002#/m#^http://mms.singtel.com:10021/mmsc#/" cellView.cpp
I got the error near "sg:" and "com:"
Can you help me?
ThanksHi,
I solved the problem. Besides, are there any command to set the starting point to replace a file.
For example,
perl -pi -i.bak -e "s/searchterm/replaceterm/" helloworld.cpp
The perl command will scan through the whole helloworld.cpp file to replace the respective strings. What if I wish the perl command start scanning the helloworld.cpp from line 10? What should I add into the command?
Thanks.
|