Sign in to follow this  
Followers 0
jnj

StringInStr

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



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?

:P


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

Share this post


Link to post
Share on other sites

I don't see anything wrong with the syntax you posted... what's the problem?

:P

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 use

If @error = -1 Then ExitLoop
inside your loop. Edited by Pain

Share this post


Link to post
Share on other sites

$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 use

If @error = -1 Then ExitLoop
inside 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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0