Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 5th October 2004, 01:32   #1
moop
Junior Member
 
Join Date: Oct 2004
Location: 127.0.0.1
Posts: 18
Send a message via Yahoo to moop
More text replacement woes...

I have read the docs. I have been searching these forums for hours. I still need help. I have installed and used the StrReplace and ReplaceInFile scripts from the Archive. I'm not a programmer by day, so bear with me, please. The closest solution to what I've found so far is HERE.

Basically, I want to do two things. I'll wait before posting the second one because hopefully I can learn how to do it from the response I get to this one.

----my text file----
asdfasdf
CDPath=F:
asdfasdf
----eof-------------

Wherein F: can be anything, from blank, to a longer string.

I have seen how to replace a full line, but not unless I match the string exactly. How can I flush the junk after the equals sign and keep the rest intact? I have used the ReplaceInFile !insertmacro, but that only works if my string matches exactly, and although I can "cheat" by inserting a $\r$\n, that still just moves the "junk" after the equals sign to another line I would still need to delete.

I'm not a programmer by day, please forgive my noobishness... This isn't second nature to me yet, and I'm certain a NSIS whiz could do what I want in 5 minutes, which has taken me... longer than I care to admit.

moop is offline   Reply With Quote
Old 5th October 2004, 17:01   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Shropshire, England
Posts: 6,887
I think this calls for another text manipulation function by Afrow!

Please bare with me and I will have one written shortly.

-Stu
Afrow UK is offline   Reply With Quote
Old 5th October 2004, 17:38   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Shropshire, England
Posts: 6,887
Done:
http://nsis.sourceforge.net/archive/...b.php?page=626

You want to do this:
code:
Push "$INSTDIR\file.ext"
Push "CDPath="
Push "CDPath=new value"
Call ReplaceLineStr



-Stu
Afrow UK is offline   Reply With Quote
Old 5th October 2004, 19:40   #4
moop
Junior Member
 
Join Date: Oct 2004
Location: 127.0.0.1
Posts: 18
Send a message via Yahoo to moop
Cool

Thanks a ton. I had gone to the IRC chatroom yesterday where Anders gave me some useful code, but most of it was greek. I still want to use it to learn though, but yours is immediately helpful. Thanks very much, Afrow! I hope I can help my community as much as you help NSIS.

moop is offline   Reply With Quote
Old 6th October 2004, 17:17   #5
razor_x
Member
 
Join Date: Feb 2004
Posts: 58
sweet afrow..can this be made into a macro too?
razor_x is offline   Reply With Quote
Old 6th October 2004, 18:03   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Shropshire, England
Posts: 6,887
...

code:

!macro ReplaceLineStr File StartStr LineStr
Push "${File}"
Push "${StartStr}"
Push "${LineStr}"
Call ReplaceLineStr
!macroend

!insertmacro ReplaceLineStr "$INSTDIR\file.ext" "CDPath=" "CDPath=new value"



-Stu
Afrow UK is offline   Reply With Quote
Old 3rd March 2010, 19:26   #7
Kolya
Junior Member
 
Join Date: Dec 2006
Posts: 7
Sorry for bumping such an old thread...

This function has been very helpful but it misses one important feature for me: If the searched string isn't found, I'd like to write the replacement string to a new line, instead of just dropping it.

I know how to add the new line at the bottom of the file, but I need help with writing that exception.
Kolya is offline   Reply With Quote
Old 4th March 2010, 22:22   #8
Kolya
Junior Member
 
Join Date: Dec 2006
Posts: 7
Some help please? Or am I missing something obvious?
Kolya is offline   Reply With Quote
Old 5th March 2010, 16:09   #9
Kolya
Junior Member
 
Join Date: Dec 2006
Posts: 7
Nevermind, I eventually used the script to delete any previously existing matching lines and then added my lines at the bottom.

This worked for me because it doesn't matter where the new lines are.
Kolya is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 22:27.