Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 2nd April 2002, 01:09   #1
amitchel_us
Junior Member
 
Join Date: Apr 2002
Posts: 2
Converting a String ($INSTDIR) from back to forward slash ( \ -> / )

I'm planning to use NSIS (which rocks) to install a Java application on WinNT/2000. The framework includes configuration files with directory listings. For example :

UPLOAD_DIR = d:/InstallDir/subDir

InstallDir is the same as NSIS' $INSTDIR. So if the user decides to install on F:\InstallDir, I want to change my configuration files to F:/InstallDir/subDir.

Java's file are either forward slash (/), or double-backslash (\\). A single backslash (\) is an escape character. So, F:\InstallDir is invalid.

Here's what I've thought of :
1. use NSIS strcmp, strcpy, strlen. I don't think this will work because there's no for..loop to loop through each character in $INSTDIR.

2. use an MS-Dos command through Exec to replace the slashes. It doesn't look like there's an easy way to do it. Win-2000's wsh may have it, but most of my customers are NT. If I could call it, though, I could probably write the result to a file and then read the file back in to get the value

3. Check this forum for similar items. I didn't see any.

Thanks in advance,
Andy
amitchel_us is offline   Reply With Quote
Old 2nd April 2002, 06:42   #2
Pomflain
Member
 
Pomflain's Avatar
 
Join Date: Aug 2001
Posts: 83
Look at the utility functions.

Look at the example for parsing $CMDLINE parameters. Instead of delimiting by ' ', just scan until you hit the \ and then do a strcat. Like this:

#Scan for parameters $R1 is the counter which points to the '\'
IntOp $R1 $R1 - 1 ; Move pointer back to point before the '\'
StrCpy $R2 "/"
StrCpy $R0 $R0 "" $R1 ; Copy until the '\'
StrCpy $R0 "$R0$R2" ; Replace the '\' with '/'

I think that should work, but I'm also sure someone else will have a much simpler solution, they always do.

Hope that helps (a little).
Pomflain is offline   Reply With Quote
Old 2nd April 2002, 14:30   #3
Smile2Me
Guest
 
Posts: n/a
Since I guess that there will be multiple '\' that need to be replaced, just scan the complete string character by character and replace if recessary will be more easy than waiting with copieng till a '\' is encountered. But that's just my guess. Otherwise you will have a loop with two possibilities and a lot of jumps. With this solution you just copie each character to a new string unless it's equal to '\'.

Take a look at the source. It's a function that replaces in a string any substring by another string (StrReplace).

I hope this will answer the question.

Good luck,
greetz, Hendri.
Attached Files
File Type: zip replchar.zip (20.1 KB, 879 views)

Last edited by Smile2Me; 2nd April 2002 at 15:23.
  Reply With Quote
Old 2nd April 2002, 16:06   #4
Smile2Me
Guest
 
Posts: n/a
I generalized the ReplChar function to a StrReplace function that replaces any substring by an other string. The statement above was not correct, the previous function only worked for substrings of length 1. That was sufficient for your problem. The new function can take substrings of any length. But anyway, take a look at the general function. I guess more people will like this one...

This function can of course also solve the problem of replacing '\' by '/'.

Good luck, greetz,
-Hendri.
Attached Files
File Type: zip strreplace.zip (20.2 KB, 946 views)
  Reply With Quote
Old 3rd April 2002, 01:30   #5
amitchel_us
Junior Member
 
Join Date: Apr 2002
Posts: 2
That's terrific. It just clicked into place once I saw how you used labels for the loops. I had no idea. Thanks for the cleverness.

Andy
amitchel_us is offline   Reply With Quote
Old 3rd April 2002, 08:07   #6
Smile2Me
Guest
 
Posts: n/a
Thx for the nice words

-Hendri.
  Reply With Quote
Old 15th January 2003, 19:46   #7
treaz
Member
 
Join Date: Jan 2003
Posts: 78
Hi,

I guess there is a silly person here who doesn't know how to integrate your StrReplace function and put it to use.

I need to replace Strings in a file, but how do I specify a file name or get your StrReplace function read my file?

Could you please advice. Thanks.
treaz is offline   Reply With Quote
Old 15th January 2003, 20:48   #8
Smile2Me
Guest
 
Posts: n/a
Read this:
http://forums.winamp.com/showthread....hreadid=121562

-Hendri.
  Reply With Quote
Reply
Go Back   Winamp & Shoutcast 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