|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 |
Senior Member
Join Date: Nov 2013
Location: Iran
Posts: 243
|
![]()
hi
for example i have a variable with this value HTML Code:
StrCpy $CFR "1--------------$\r$\n2-Which is the best CPU scheduling algorithm?$\r$\n3-CPU Scheduler$\r$\n4-I/O request or invocation$\r$\n5--------------" and read that line first character (4) |
![]() |
![]() |
![]() |
#2 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,701
|
You have been around for a while now so you know that NSIS has some word and string macros you can try and if those are not enough then you can build your own with StrCpy+StrCmp+StrLen...
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#3 | |
Senior Member
Join Date: Nov 2013
Location: Iran
Posts: 243
|
Quote:
i have big problem ![]() i use from StrRep function to find word but i cant edit that for find line number HTML Code:
Var C0 Var C1 Var C2 Var C3 Var C4 Var C5 Var C6 Var C7 Var C8 Var C9 Var VCR Var VCR2 Var VCR3 Var String !define LineCode '$\r$\n' !define StrRep "!insertmacro StrRep" !macro StrRep output string old new Push `${string}` Push `${old}` Push `${new}` !ifdef __UNINSTALL__ Call un.StrRep !else Call StrRep !endif Pop ${output} !macroend !macro Func_StrRep un Function ${un}StrRep Exch $R2 ;new Exch 1 Exch $R1 ;old Exch 2 Exch $R0 ;string Push $R3 Push $R4 Push $R5 Push $R6 Push $R7 Push $R8 Push $R9 StrCpy $R3 0 StrLen $R4 $R1 StrLen $R6 $R0 StrLen $R9 $R2 ;$R2 ;new ;$R1 ;old ;$R0 ;string ;$R2 = Removed ;$R1 = ${LineCode} ;$R0 = Not Change StrCpy $C3 0 StrLen $C4 ${LineCode} StrLen $C6 $R0 loop: StrCpy $R5 $R0 $R4 $R3 ;-------------------------------------- StrCpy $C5 $R0 $C4 $C3 StrCmp $C5 ${LineCode} found2 IntOp $C3 $C3 + 1 ;move offset by 1 to check the next character Back1: ;-------------------------------------- StrCmp $R5 $R1 found StrCmp $R3 $R6 done IntOp $R3 $R3 + 1 ;move offset by 1 to check the next character Goto loop found: StrCpy $R5 $R0 $R3 IntOp $R8 $R3 + $R4 StrCpy $R7 $R0 "" $R8 StrCpy $R0 $R5$R2$R7 StrLen $R6 $R0 IntOp $R3 $R3 + $R9 ;move offset by length of the replacement string Goto loop found2: StrCpy $C5 $R0 $C3 IntOp $C8 $C3 + $C4 StrCpy $C7 $R0 "" $C8 StrCpy $R0 $C5$C7 StrLen $C6 $R0 IntOp $C3 $C3 + $C9 ;move offset by length of the replacement string IntOp $VCR $VCR + 1 StrCpy $VCR2 $VCR2$VCR, Goto Back1 done: MessageBox MB_OK "[$VCR # $VCR2 # $VCR3 # $R0_$R1_$R2_$R3_$R4_$R5_$R6_$R7_$R8_$R9 # $C0_$C1_$C2_$C3_$C4_$C5_$C6_$C7_$C8_$C9]" Pop $R9 Pop $R8 Pop $R7 Pop $R6 Pop $R5 Pop $R4 Pop $R3 Push $R0 Push $R1 Pop $R0 Pop $R1 Pop $R0 Pop $R2 Exch $R1 FunctionEnd !macroend !insertmacro Func_StrRep "" !insertmacro Func_StrRep "un." Section ;MessageBox MB_OK "[$VCR # $VCR2 # $VCR3 # $R0_$R1_$R2_$R3_$R4_$R5_$R6_$R7_$R8_$R9 # $C0_$C1_$C2_$C3_$C4_$C5_$C6_$C7_$C8_$C9]" StrCpy $R2 '%%%%' StrCpy $R1 'invocation' ; StrCpy $String "1--------------$\r$\n2-Which is the best CPU scheduling algorithm?$\r$\n3-CPU Scheduler$\r$\n4-I/O request or invocation$\r$\n5--------------" ${StrRep} '$0' '$String' '$R1' '$R2' MessageBox MB_OK "$0" SectionEnd Last edited by r2du-soft; 14th July 2017 at 08:20. |
|
![]() |
![]() |
![]() |
#4 |
Senior Member
Join Date: Nov 2013
Location: Iran
Posts: 243
|
how should i do change the:
FileOpen $R2 $R1 r & FileRead $R2 $R3 for support variable this function? HTML Code:
Var String Function FileSearch Pop $7 ;~~~~Piotrek occurance numberw Exch $R0 ;search for Exch Exch $R1 ;input file Push $R2 Push $R3 Push $R4 Push $R5 Push $R6 Push $R7 Push $R8 Push $R9 StrLen $R4 $R0 StrCpy $R7 0 StrCpy $R8 0 ;~~~~Piotrek start StrCpy $9 0 ${If} $7 == "" StrCpy $7 0 ; occurence number user specified ${EndIf} ;~~~~Piotrek end ClearErrors FileOpen $R2 $R1 r IfErrors Done LoopRead: ClearErrors FileRead $R2 $R3 IfErrors DoneRead IntOp $9 $9 + 1 ;Piotrek ;MessageBox MB_OK "$9" IntOp $R7 $R7 + 1 StrCpy $R5 -1 StrCpy $R9 0 LoopParse: IntOp $R5 $R5 + 1 StrCpy $R6 $R3 $R4 $R5 StrCmp $R6 "" 0 +4 StrCmp $R9 1 LoopRead IntOp $R7 $R7 - 1 Goto LoopRead StrCmp $R6 $R0 0 LoopParse StrCpy $R9 1 IntOp $R8 $R8 + 1 ;~~~~Piotrek start ${If} $R8 == $7 ;if occurence is specified - outputs a specified occurence if not last occurence is output***93; StrCpy $0 $9 StrCpy $7 "-1" ${ElseIf} $7 == 0 StrCpy $0 $9 ${EndIf} ;~~~~Piotrek end Goto LoopParse DoneRead: ;MessageBox MB_OK "[$0]_[$1]_[$2]_[$3]_[$4]_[$5]_[$6]_[$7]_[$8]_[$9]_[$R1]_[$R2]_[$R3]_[$R4]_[$R5]_[$R6]_[$R7]_[$R8]_[$R9]" MessageBox MB_OK "1.First String In Line: $0 \ $\r$\n2.Find String In Line: $9 \ $\r$\n3.Line $9 String IS: $R3 \ $\r$\n4.Find String $R8 Time." FileClose $R2 Done: StrCpy $R0 $R8 StrCpy $R1 $R7 Pop $R9 Pop $R8 Pop $R7 Pop $R6 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 ;number of lines found on Exch Exch $R0 ;output count found Push $0 ;You need to pop that out after function call as first parameter ````Piotrek FunctionEnd Section StrCpy $String "1--------------$\r$\n2-Which is the best CPU scheduling algorithm?$\r$\n3-CPU Scheduler$\r$\n4-I/O request or invocation$\r$\n5--------------" Push "$String" Push "invocation" Push 1 # line should be displayed for occurance number of the searched string, if empty string is passed or 0 the last occurance will be displayed Call FileSearch SectionEnd |
![]() |
![]() |
![]() |
#5 |
Senior Member
Join Date: Nov 2013
Location: Iran
Posts: 243
|
Problem Solved
my problem solved
i just need Find the first word available this code have some bugs but my problem solved. HTML Code:
!include "x64.nsh" !include "StrCount.nsh" Var String Var LineReaded Var FindWord Section StrCpy $FindWord "Rose" #Searching String In Variable StrCpy $String "1--------------$\r$\n2-Which is the invocation best CPU scheduling algorithm?$\r$\n3-CPU Scheduler$\r$\n4-I/O request or invocation$\r$\n5--------------$\r$\nRose" ;------------------------------------------------------------ StrCpy $1 0 StrCpy $5 0 StrCpy $6 0 ;------ loop: IntOp $6 $6 + 1 StrCpy $2 $String 1 $1 ;------------------- /* ${If} $2 == "$\r$\n" IntOp $6 $6 - 2 ${ElseIf} $2 == "$\n" ${OrIf} $2 == "$\r" IntOp $6 $6 - 1 ${EndIf} */ ;------------------- IntOp $1 $1 + 1 StrCmp $2 '$\n' found StrCmp $2 '' found loop IntOp $5 $5 + 1 ;------ found: IntOp $3 $3 + 1 StrCpy $LineReaded $String $6 $5 StrCpy $5 "" StrCpy $6 "" ;------------------------------------------------------------ ${StrCount} "$LineReaded" "$FindWord" "i" Pop $0 ;-------- ${If} $0 != "0" StrCpy $4 "$LineReaded" 1 ${else} StrCpy $5 $1 Goto loop #read Next Line ${endIf} ;------------------------------------------------------------ ;--------------------------------- MessageBox MB_OK "You Searched For: $FindWord \ $\r$\nFind [$0] Time \ $\r$\nFind At Line [$3] \ $\r$\nLine $3 String IS: [$LineReaded] \ $\r$\nLine $3 First Char IS: [$4]" ;--------------------------------- SectionEnd |
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|