hi, is it possible to read a word from a line?
Example: This is a cat.
If i want to read only the 2nd word, how do i do it??
I had used lineread, but it only read a whole line.
Is there any way to read just 1 word from a line??
Read a word from a line
35 posts
Hi Alstom!
Have a look at those functions
especially WordFind
Have a nice day!
Cheers
Bruno
Have a look at those functions
especially WordFind
Have a nice day!
Cheers
Bruno
Thx Bruno
But is it possible to read a word on a line that would constantly be changed by the user?
Like on which line and which word to be read.
This is actually what i wanted to get.
But is it possible to read a word on a line that would constantly be changed by the user?
Like on which line and which word to be read.
This is actually what i wanted to get.
Yes, of course.
Just read the line with
${LineRead} "[File]" "$LineNumber" $var
and use
${WordFind} $var "[delimiter]" "$WordNumber" $R0
You can change $LineNumber and $WordNumber at runtime.
Otherwise post some real-world examples.
Just read the line with
${LineRead} "[File]" "$LineNumber" $var
and use
${WordFind} $var "[delimiter]" "$WordNumber" $R0
You can change $LineNumber and $WordNumber at runtime.
Otherwise post some real-world examples.
ok, so how do i use it? What is [delimiter]?? $WordNumber is the number of the word in the sentence??
I would be changing the word in a few sentences in a file and the installer would be able to call the file to read the word i would be changing.
Could you show me a example to use this two together??
Example:
This is his dog.
How to alway read only the second word {is} or any word replacing the {is} in the sentence which could be changed anytime.
Do you understand my Q? Sorry, my english is not so gd. 😉
I would be changing the word in a few sentences in a file and the installer would be able to call the file to read the word i would be changing.
Could you show me a example to use this two together??
Example:
This is his dog.
How to alway read only the second word {is} or any word replacing the {is} in the sentence which could be changed anytime.
Do you understand my Q? Sorry, my english is not so gd. 😉
This might help you:
Content of file test.txt before:
;--------------------------------
;Include Modern UI
!include "MUI.nsh"
;--------------------------------
;General
Outfile test.exe
;--------------------------------
;Pages
!insertmacro MUI_PAGE_INSTFILES
;--------------------------------
;including files
!include TextFunc.nsh
!insertmacro LineFind
!include WordFunc.nsh
!insertmacro WordReplace
!insertmacro WordFind
Function "MyFunction"
; $R9 current line
; $R8 current line number
; $R7 current line negative number
; $R6 current range of lines
; $R5 handle of a file opened to read
; $R4 handle of a file opened to write ($R4="" if "/NUL")
; you can use any string functions
; $R0-$R3 are not used (save data in them).
; ...
${WordFind} "$R9" " " "+2" $R0 ; get the second word
${WordReplace} $R9 " $R0 " " was " "+" $R9 ; replace the word (including delimiters)
Push $0 ; If $var="StopLineFind" Then exit from function
; If $var="SkipWrite" Then skip current line (ignored if "/NUL")
FunctionEnd
Section "secDummy"
${LineFind} "test.txt" "" "2" "MyFunction" ; 2 = line number
SectionEnd
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
Content of file test.txt after:
This is my cat.
This is my dog.
This is my cow.
This is my cat.
This was my dog.
This is my cow.
Hi , that was great!! Now i would wish to do a loop to read a file and get some content in the file til end of file.
How do i write the loop??
Example:
Read the file
While(Not end of file)
Do line read
Do Word find
IF $R1 ;value of the word
Do ..........
Else
Do ..........
How do i write the actual code for this??
How do i write the loop??
Example:
Read the file
While(Not end of file)
Do line read
Do Word find
IF $R1 ;value of the word
Do ..........
Else
Do ..........
How do i write the actual code for this??
Hi Alstom!
To achieve this, just read the documentation for LineFind at [1] and use the skeleton provided above.
Bruno
[1] http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.2
To achieve this, just read the documentation for LineFind at [1] and use the skeleton provided above.
Cheers
${LineFind} "test.txt" "" "1:-1" "MyFunction"
Bruno
[1] http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.2
Hi, I am able to do the lineread and wordfind to get the word i want but how to do a loop for a file with many lines to check the word and call a function if it is the word i want.
If $R1 = A
Do .....
If $R1 = A
Do .....
hi, maybe i put a simple example of what i want to do below.
Example:
WHILE ($R0 != END OF FILE)
${WordFind} "$R1 " "," "-2" $R1 ; Read the last 2nd word from current line
IF $R1 = A
CopyFiles "$DESKTOP\file.exe" "$OUTDIR"
ExecWait "$OUTDIR\file.exe"
ELSE
MessageBox MB_Ok "$$R1 not correct"
$R1++ ;go to next line
Example:
WHILE ($R0 != END OF FILE)
${WordFind} "$R1 " "," "-2" $R1 ; Read the last 2nd word from current line
IF $R1 = A
CopyFiles "$DESKTOP\file.exe" "$OUTDIR"
ExecWait "$OUTDIR\file.exe"
ELSE
MessageBox MB_Ok "$$R1 not correct"
$R1++ ;go to next line
The third parameter of LineFind is to specify the range of lines you want to read! You don't need to use something like while!
I think you want to parse a licence file. You could parse your license file in .onInit with LineFind and activate the sections with SelectSection from Sections.nsh. If you want to use the components dialog as well just add hidden sections to your script, which you enable from the license file, and show those the user is allowed to choose.
How to write not end of file in a while loop??
${WHILE} R0 != end of file??
What the code for end of file??
${WHILE} R0 != end of file??
What the code for end of file??
Here you are:
1:-1 symbolises the whole file
${LineFind} "test.txt" "" "1:-1" "MyFunction"
i just wan the end of the file.
for while loop.
While $R1 < "end of file"
for while loop.
While $R1 < "end of file"
sorry but not able to work when i i wan to put it in a while loop. how to let the loop go to the end of file??
i have put a $R0 $R0 + 1 before the end of the loop to go to the next line but how to go to the last line of the line to stop??
for the moment , i put :
WHILE $R0 <100
but how to replace the 100 with the end of file???
i have put a $R0 $R0 + 1 before the end of the loop to go to the next line but how to go to the last line of the line to stop??
for the moment , i put :
WHILE $R0 <100
but how to replace the 100 with the end of file???
Actually, I don't understand why you want to use a while loop! Just use LineFind, that's great.
i using a line read and wordfind to go from a line to the other line 1 by 1 to call some function if the word is found on each line.
Ok, have a look at the post from 23. November.
LineFind is even better because you don't have to worry about the size of the file. LineFind calls your function for every line you specify and you get the index in a variable in the function:
; $R9 current line <--
; $R8 current line number <---
; $R7 current line negative number
; $R6 current range of lines
; $R5 handle of a file opened to read
; $R4 handle of a file opened to write ($R4="" if "/NUL")
This calls MyFunction for every line in the file. If you need only the last, just adjust the range as you see in the docs.
${LineFind} "test.txt" "" "1:-1" "MyFunction"
LineFind is even better because you don't have to worry about the size of the file. LineFind calls your function for every line you specify and you get the index in a variable in the function:
; $R9 current line <--
; $R8 current line number <---
; $R7 current line negative number
; $R6 current range of lines
; $R5 handle of a file opened to read
; $R4 handle of a file opened to write ($R4="" if "/NUL")
This calls MyFunction for every line in the file. If you need only the last, just adjust the range as you see in the docs.
${LineFind} "test.txt" "" "1:-1" "MyFunction"
Hi bholliger,
I has problems which related with WordFind and I post my question here.
I also try with your example which you posted above.
I try with it and it do well except one case.
Firstly, I try with this
However, I try with this "Url = jdbc:mysql://127.0.0.1:3306/Openim" Nothing change after I run your code above!
${WORDFIND}is not work in my case, is it?
Can you help me!
My word is too bad, if you do not understand.Please tell me!
Thank in advance,
I has problems which related with WordFind and I post my question here.
I also try with your example which you posted above.
I try with it and it do well except one case.
I has put this line in file text in c:\test.txt
Url = jdbc:mysql://127.0.0.1:3306/Openim
Firstly, I try with this
This is my catAnd I can put "jdbc:mysql://127.0.0.1:3306/Openim" in "THIS IS MY CAT" to become "THIS jdbc:mysql://127.0.0.1:3306/Openim MY CAT"
However, I try with this "Url = jdbc:mysql://127.0.0.1:3306/Openim" Nothing change after I run your code above!
${WORDFIND}is not work in my case, is it?
Can you help me!
My word is too bad, if you do not understand.Please tell me!
Thank in advance,
Sorry, I don't get what you want to achieve.
Could you explain it in another way? What do you want to change in your URL = ...?
Could you explain it in another way? What do you want to change in your URL = ...?
Hi bholliger,
I want to change URL to run my webadmin if they run webadmin in their computer or they run it on the other computer. So, I need IP address and change URL.
I try your code and I change to like this
Username = root or Password = 123456
[
With WORDFIND and WORDREPLACE, I can not do if in my text has "="
I do not know why it is not work?
If you know, please tell me!
Thank in advance,
I want to change URL to run my webadmin if they run webadmin in their computer or they run it on the other computer. So, I need IP address and change URL.
I try your code and I change to like this
My test.txt
Function "MyFunction"
; $R9 current line
; $R8 current line number
; $R7 current line negative number
; $R6 current range of lines
; $R5 handle of a file opened to read
; $R4 handle of a file opened to write ($R4="" if "/NUL")
; you can use any string functions
; $R0-$R3 are not used (save data in them).
; ...
${WordFind} "$R9" " " "+3" $R0 ; get the third word
MessageBOx MB_OK "$$R9 (string): $R9"
MessageBOx MB_OK "$$R0 (word to replace): $R0"
${WordReplace} $R9 " $R0 " " jdbc:mysql://193.168.75.124:3306/Openim " "+" $R9 ; replace the word (including delimiters)
MessageBOx MB_OK "$$R9 after replace: $R9"
Push $0 ; If $var="StopLineFind" Then exit from function
; If $var="SkipWrite" Then skip current line (ignored if "/NUL")
FunctionEnd
Section "secDummy"
${LineFind} "c:\test.txt" "" "4" "MyFunction" ; 2 = line number
SectionEnd
This is one case which I must change in file webadmin. Also,I can not change it although I try with other case like
This is my cat.
This was my dog
This is my cow.
Url = jdbc:mysql://127.0.0.1:3306/Openim
Username = root or Password = 123456
[
With WORDFIND and WORDREPLACE, I can not do if in my text has "="
I do not know why it is not work?
If you know, please tell me!
Thank in advance,
For your sample I'd use WordFind2X because there is a certain structure. :// and :
[1] http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.9
Have fun!
Cheers
Bruno
If you have a file with this structure:
StrCpy $R2 "192.168.0.24" ; new IP
${WordFind2X} "$R9" "://" ":" "+1" $R0 ; get current value
MessageBOx MB_OK "$$R9 (string): $R9"
MessageBOx MB_OK "$$R0 (word to replace): $R0"
MessageBOx MB_OK "$$R2 (IP): $R2"
${WordReplace} $R9 "$R0" "$R2" "+" $R9
MessageBOx MB_OK "$$R9 after replace: $R9"
use ConfigRead and ConfigWrite from [1]. It's a lot easier and you don't have to filter or know where your value in the file is.
Username = root
Password = 123456
[1] http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.9
Have fun!
Cheers
Bruno
Thank bholliger very much for your help
Now I can solve my problems
🙂
Now I can solve my problems
🙂
You're welcome! :-)
Hi bholliger 🙂
I still have one question which is related with change word in file.
My file which I intend to change it influence my application.
If I change some words by hand in that file, I can run my web well. But I try with $WORDFIND, $CONFIGWRITE and $WORDREPLACE, at that time, my application is error when it runs.
I do not know why although I check file which I change.It's ok.
I wonder I use $WORDFIND... in NSIS does it display some characters in my file and it also is problems which my application is not run when I repair it.
Did you use to see this problem? I also search these errors on google but they just said "it is problem in software".In my mind, I do not think so.
Do you have any opinions about my case?
Thank a lot for your help,
🙂
I still have one question which is related with change word in file.
My file which I intend to change it influence my application.
If I change some words by hand in that file, I can run my web well. But I try with $WORDFIND, $CONFIGWRITE and $WORDREPLACE, at that time, my application is error when it runs.
I do not know why although I check file which I change.It's ok.
I wonder I use $WORDFIND... in NSIS does it display some characters in my file and it also is problems which my application is not run when I repair it.
Did you use to see this problem? I also search these errors on google but they just said "it is problem in software".In my mind, I do not think so.
Do you have any opinions about my case?
Thank a lot for your help,
🙂
Could you post your code, please?
How does the file look before/after?
How does the file look before/after?
Thank bholliger,
My code here:
[QUOTE]
Driver = com.mysql.jdbc.Driver
Url = jdbc:mysql://127.0.0.1:3306/Openim
Username = root
Password = 123456
domainname=wwtkk.com
RootUser=rootadm
RootPassword=password
{/QUOTE]
My file after I execute my installer
If you know, please tell me why?
Thank in advance,
My code here:
File before I change
Function Replace
StrCpy $R2 $IP ;new IP
Detailprint "$$IP : $IP"
${WordFind2X} "$R9" "://" ":" "+1" $R0 ; get current value
Detailprint "$$R9 truoc khi thay the: $R9"
Detailprint "$$R0 tu de thay the: $R0"
Detailprint "$$R2 (IP): $R2"
${WordReplace} $R9 "$R0" "$R2" "+" $R9
; ${WordReplace} $R9 " $R0 " " jdbc:mysql://127.0.0.1:3306/Openim " "+" $R9 ; replace the word (including delimiters)
Detailprint "$$R9 sau khi thay the: $R9"
Push $0 ; If $var="StopLineFind" Then exit from function
; If $var="SkipWrite" Then skip current line (ignored if "/NUL")
FunctionEnd
InstallDirRegKey HKLM "SOFTWARE\Apache Software Foundation\Tomcat\5.5" "InstallPath"
Section EditFile
StrCpy $IP "localhost"
StrCpy $root "root"
StrCpy $passroot "123456"
StrCpy $domain "telnet.com"
StrCpy $useradmin "admin"
StrCpy $passadmin "password"
nsExec::Exec 'net stop "Apache Tomcat 5"'
Detailprint "Stop Tomcat successfull"
StrCpy $Path "$INSTDIR\webapps\webadmin\WEB-INF\classes\ApplicationResources.properties"
Detailprint "$$Path :$Path"
#### Change hostname
${LineFind} "$Path" "" "2" "Replace" ; 2 = line number
#### Change root and password of database
${ConfigWrite} "$Path" "Username" " = $root" $1
Detailprint "$$1: $1"
${ConfigWrite} "$Path" "Password" " = $passroot" $1
Detailprint "$$1: $1"
#### Change Domain
${ConfigWrite} "$Path" "domainname" "=$domain" $1
Detailprint "$$1: $1"
#### Change rootuser and passworduser
; StrCpy $domain "adminroot"
${ConfigWrite} "$Path" "Rootuser" "=$useradmin" $1
Detailprint "$$1: $1"
${ConfigWrite} "$Path" "Rootpassword" "=$passadmin" $1
Detailprint "$$1: $1"
nsExec::Exec 'net start "Apache Tomcat 5"'
SectionEnd
[QUOTE]
Driver = com.mysql.jdbc.Driver
Url = jdbc:mysql://127.0.0.1:3306/Openim
Username = root
Password = 123456
domainname=wwtkk.com
RootUser=rootadm
RootPassword=password
{/QUOTE]
My file after I execute my installer
Driver = com.mysql.jdbc.DriverI only change these lines in my file. I can not explain why if I install with my installer,my web application is error. When I change by hand, it works well.
Url = jdbc:mysql://localhost:3306/Openim
Username = root
Password = 123456
domainname=telnet.com
RootUser=admin
RootPassword=password
If you know, please tell me why?
Thank in advance,
What's the error message of the application? Is your computer resolving the localhost correctly to 127.0.0.1?
Although this is not the root of the problem, I'd use ConfigWrite like that:
${ConfigWrite} "$Path" "Rootuser=" "$useradmin" $1
and I'd use ${ConfigRead} to read the value of Url=, otherwise you have to make sure that this setting always appears on the second line.
Although this is not the root of the problem, I'd use ConfigWrite like that:
${ConfigWrite} "$Path" "Rootuser=" "$useradmin" $1
and I'd use ${ConfigRead} to read the value of Url=, otherwise you have to make sure that this setting always appears on the second line.