Old 19th February 2008, 04:43   #1
oliverbob
Junior Member
 
Join Date: Feb 2008
Posts: 13
Question Newbie question about string replace

Hello world,

I wanted to replace the back slashes with forward slashes of this string:

H:\dir1\dir2\dir3\myProgram\index.html

So that the output should look like this:

H:/dir1/dir2/dir3/myProgram/index.html

How do I do this? Can somebody share their experties in this? I would appreciate some example code.

Last edited by oliverbob; 19th February 2008 at 07:00.
oliverbob is offline   Reply With Quote
Old 19th February 2008, 06:33   #2
oliverbob
Junior Member
 
Join Date: Feb 2008
Posts: 13
Here is the code I have as a follow up of the previous post.

___________________________________

; Java Launcher
;--------------

Name "Java Launcher"
Caption "Java Launcher"
Icon "modern-install.ico"
OutFile "Java Launcher.exe"

SilentInstall silent
AutoCloseWindow true
ShowInstDetails nevershow

!define CLASSPATH ".;lib;lib\HyperLink.jar"
!define CLASS "demo.Demo"

Section ""
Call GetJRE
Pop $R0

; change for your purpose (-jar etc.)
StrCpy $0 '"$R0" -classpath "${CLASSPATH}" ${CLASS}'

SetOutPath $EXEDIR
Exec $0
SectionEnd

Function GetJRE
;
; Find JRE (javaw.exe)
; 1 - in .\jre directory (JRE Installed with application)
; 2 - in JAVA_HOME environment variable
; 3 - in the registry
; 4 - assume javaw.exe in current dir or PATH

Push $R0
Push $R1

ClearErrors
StrCpy $R0 "$EXEDIR\jre\bin\javaw.exe"
IfFileExists $R0 JreFound
StrCpy $R0 ""

ClearErrors
ReadEnvStr $R0 "JAVA_HOME"
StrCpy $R0 "$R0\bin\javaw.exe"
IfErrors 0 JreFound

ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion"
ReadRegStr $R0 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$R1" "JavaHome"
StrCpy $R0 "$R0\bin\javaw.exe"

IfErrors 0 JreFound
StrCpy $R0 "javaw.exe"

JreFound:
Pop $R1
Exch $R0

FileOpen $9 Init.properties w ;Opens a Empty File and fills it
FileWrite $9 "$EXEDIR/index.html" ;--what I wanted to replace by changing the "\" occurences with "/"
; current output is: H:\dir\dir\dir/index.html

FileClose $9 ;Closes the filled file

FunctionEnd
_______________________________________


Please help me.
oliverbob is offline   Reply With Quote
Old 19th February 2008, 08:03   #3
Mr Inches
Member
 
Join Date: Jan 2006
Location: Canberra, Australia
Posts: 76
Hi

Here is an example script using the StrFunc header (included as part of an NSIS install):

code:

Name "Replace String Test"

ShowInstDetails Show

OutFile 'ReplaceTest.exe'

!include "StrFunc.nsh"

; 'Declare' functions used in StrFunc.nsh
${StrRep}

Section "-Main"

StrCpy $R0 "C:\TEMP\FOLDER"
${StrRep} $R1 $R0 "\" "/"
DetailPrint "$R0 -> $R1"

SectionEnd




Duncan
Mr Inches is offline   Reply With Quote
Old 19th February 2008, 08:58   #4
oliverbob
Junior Member
 
Join Date: Feb 2008
Posts: 13
That was so helpful Duncan

Thanks a lot for your kindness to help.

I have tried the code, and it is so helpful and I just discover the benifit of using HM NIS Edit.

This evening I will explore and study about NSIS with it.
This two tools are entirely useful with my Java Projects.

Once again thank you very much.


Bob
oliverbob is offline   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