jnj Posted October 23, 2008 Posted October 23, 2008 Hi, How can use StringInStr when a string and substring are two variables. Reading the contents from File 1 and put the part wanted in a variable. $Line1 = FileReadLine($File1) $Var = StringMid ($Line1 , 18,4) By reading File 2 and searching per line I'd like to check if the content of "Var" is in File 2 $Line2 = FileReadLine($File2) If StringInStr($Line2, $Var) Then Many thanks in advance for any help given on this matter.
PsaltyDS Posted October 23, 2008 Posted October 23, 2008 Hi,How can use StringInStr when a string and substring are two variables.Reading the contents from File 1 and put the part wanted in a variable.$Line1 = FileReadLine($File1)$Var = StringMid ($Line1 , 18,4) By reading File 2 and searching per line I'd like to check if the content of "Var" is in File 2$Line2 = FileReadLine($File2)If StringInStr($Line2, $Var) Then Many thanks in advance for any help given on this matter.I don't see anything wrong with the syntax you posted... what's the problem? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
jnj Posted October 23, 2008 Author Posted October 23, 2008 I don't see anything wrong with the syntax you posted... what's the problem? Thanks for your swiftly reply PsaltyDS.Well,the next command would be, for instance, a ConsoleWrite showing the entire line but somehow it goes to Else instead of execute what is In If.. Then block.The files are TXT files and I know that the value on $Var is in the other file. Am I missing something?Many thanks again.
Pain Posted October 23, 2008 Posted October 23, 2008 (edited) $Line1 = "Hello world! bla blaa bla test." $Var = StringMid ($Line1 , 18,4) ;this returns "blaa" $Line2 = "blaa bla bla bla test test test" If StringInStr($Line2, $Var) Then ;this will write "found" because you can find "blaa" in $Line2 ConsoleWrite("Found") Else ConsoleWrite("Not found") EndIf btw. also keep in mind that if you use FileReadLine you need a loop to loop all lines and not only the first one. To stop it useIf @error = -1 Then ExitLoopinside your loop. Edited October 23, 2008 by Pain
jnj Posted October 23, 2008 Author Posted October 23, 2008 $Line1 = "Hello world! bla blaa bla test." $Var = StringMid ($Line1 , 18,4) ;this returns "blaa" $Line2 = "blaa bla bla bla test test test" If StringInStr($Line2, $Var) Then ;this will write "found" because you can find "blaa" in $Line2 ConsoleWrite("Found") Else ConsoleWrite("Not found") EndIf btw. also keep in mind that if you use FileReadLine you need a loop to loop all lines and not only the first one. To stop it useIf @error = -1 Then ExitLoopinside your loop. Thanks for you clarification on that Pain but makes any difference if the content of that variable are numbers instead of letters? Or maybe the way that I'm doing the loop to read line by line?
Pain Posted October 23, 2008 Posted October 23, 2008 It wouldn't make any difference if the variable contains numbers, letters or mixed up with both. However in your script you never posted any loop so I assume that's why it doesn't work. $file = FileOpen("Test.txt", 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop;try comment out this line. Warning! make sure you can escape it somehow like exit from the trayicon. consolewrite($line) Wend
jnj Posted October 24, 2008 Author Posted October 24, 2008 It wouldn't make any difference if the variable contains numbers, letters or mixed up with both. However in your script you never posted any loop so I assume that's why it doesn't work. $file = FileOpen("Test.txt", 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop;try comment out this line. Warning! make sure you can escape it somehow like exit from the trayicon. consolewrite($line) Wend I got it now. Pain, many thanks for your help. Cheers.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now