WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Converting a String ($INSTDIR) from back to forward slash ( \ -> / )
  Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
amitchel_us
Junior Member

Registered: Apr 2002
From:

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

Quick Link | Report this post to a moderator | IP: Logged

amitchel_us is offline Old Post 04-02-2002 12:09 AM
Click Here to See the Profile for amitchel_us Find more posts by amitchel_us Add amitchel_us to your buddy list Edit/Delete Message Reply w/Quote
Pomflain
Member

Registered: Aug 2001
From:

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

__________________
!macro KUZU_RYU_SEN
Exec "Karatake", Exec "Kesagiri", Exec "Sakagesa", Exec "Hidari Nagi",
Exec "Migi Nagi", Exec "Hidari Kiriage", Exec "Migi Kiriage", Exec "Sakakaza", Exec "Tsuki"

MessageBox MB_OK|MB_TOPMOST "KUZU RYU SEN!!!"
!macroend

Quick Link | Report this post to a moderator | IP: Logged

Pomflain is offline Old Post 04-02-2002 05:42 AM
Click Here to See the Profile for Pomflain Click here to Send Pomflain a Private Message Find more posts by Pomflain Add Pomflain to your buddy list Edit/Delete Message Reply w/Quote
Smile2Me
Saves you...
(Alumni)

Registered: Nov 2001
From:

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.

Attachment: replchar.zip
This has been downloaded 456 time(s).

__________________
- Smile2Me -
ToDoList 3.0 available for download! (Created entirely using NSIS 2.0a6.)

Last edited by Smile2Me on 04-02-2002 at 02:23 PM

Quick Link | Report this post to a moderator | IP: Logged

Smile2Me is offline Old Post 04-02-2002 01:30 PM
Click Here to See the Profile for Smile2Me Click here to Send Smile2Me a Private Message Find more posts by Smile2Me Add Smile2Me to your buddy list Edit/Delete Message Reply w/Quote
Smile2Me
Saves you...
(Alumni)

Registered: Nov 2001
From:

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.

Attachment: strreplace.zip
This has been downloaded 434 time(s).

__________________
- Smile2Me -
ToDoList 3.0 available for download! (Created entirely using NSIS 2.0a6.)

Quick Link | Report this post to a moderator | IP: Logged

Smile2Me is offline Old Post 04-02-2002 03:06 PM
Click Here to See the Profile for Smile2Me Click here to Send Smile2Me a Private Message Find more posts by Smile2Me Add Smile2Me to your buddy list Edit/Delete Message Reply w/Quote
amitchel_us
Junior Member

Registered: Apr 2002
From:

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

Quick Link | Report this post to a moderator | IP: Logged

amitchel_us is offline Old Post 04-03-2002 12:30 AM
Click Here to See the Profile for amitchel_us Find more posts by amitchel_us Add amitchel_us to your buddy list Edit/Delete Message Reply w/Quote
Smile2Me
Saves you...
(Alumni)

Registered: Nov 2001
From:

Thx for the nice words

-Hendri.

__________________
- Smile2Me -
ToDoList 3.0 available for download! (Created entirely using NSIS 2.0a6.)

Quick Link | Report this post to a moderator | IP: Logged

Smile2Me is offline Old Post 04-03-2002 07:07 AM
Click Here to See the Profile for Smile2Me Click here to Send Smile2Me a Private Message Find more posts by Smile2Me Add Smile2Me to your buddy list Edit/Delete Message Reply w/Quote
treaz
Member

Registered: Jan 2003
From:

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.

Quick Link | Report this post to a moderator | IP: Logged

treaz is offline Old Post 01-15-2003 07:46 PM
Click Here to See the Profile for treaz Click here to Send treaz a Private Message Visit treaz's homepage! Find more posts by treaz Add treaz to your buddy list Edit/Delete Message Reply w/Quote
Smile2Me
Saves you...
(Alumni)

Registered: Nov 2001
From:

Read this:
http://forums.winamp.com/showthread...threadid=121562

-Hendri.

__________________
- Smile2Me -
ToDoList 3.0 available for download! (Created entirely using NSIS 2.0a6.)

Quick Link | Report this post to a moderator | IP: Logged

Smile2Me is offline Old Post 01-15-2003 08:48 PM
Click Here to See the Profile for Smile2Me Click here to Send Smile2Me a Private Message Find more posts by Smile2Me Add Smile2Me to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 08:44 PM. Post New Thread    Post A Reply
  Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > Converting a String ($INSTDIR) from back to forward slash ( \ -> / )
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON