Sign in to follow this  
Followers 0
kctvt

Problem with StringInStr

5 posts in this topic

#1 ·  Posted (edited)

Hi there, I'm having a problem with StringInStr. So, I need help.

This is my code :

$Friend = FileRead("Friend.txt") ;;;Problem here !!!!!!!!!!!
$Colour = FileRead("Colour.txt") ;;;Problem here !!!!!!!!!!! 


$sText = _IEBodyReadText ($oIE)

Select
    Case StringInStr($sText, $Colour&"is colour.")
        Msgbox (48, "Notice","Yes, that's true" ,5)
    Case StringInStr($sText, $Friend&"is my friend")
        Msgbox (48, "Notice","Yes, that's true." ,5)
EndSelect

Content of Friend.txt :

Peter
Daisy
Tommy
Luxi
Frank

Content of Colour.txt :

Black
White
Red
Blue
Green

I want If the code read form $oIE : "Peter is my friend"

Box --> "Yes, that's true"

and If the code read form $oIE : "Black is colour"

Box --> "Yes, that's true"

But... my problem is I cant make this code undertand it must take data from Colour.txt, and Friend.txt

So... In this case, what should I do ?

Edited by kctvt

Share this post


Link to post
Share on other sites



You need to test for the value of each record in the file, not the whole file content!

You could read the files into a Array and then loop through each array value and perform the test.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Doing it your way you will have to read those files to arrays and then loop through them. Also you left out the space before the word "is" in your StringInStr() calls

Should be StringInStr($sText, $Colour & " is colour.")

A better way would be to use StringRegExp() for both files

$sExpFriends = StringReplace(StringStripCR(FileRead("Friend.txt"), @LF, "|")
If StringRegExp($sText, "(?i)(?m:^)" & $sExpFriends & "\s*is\smy\sfriend")  Then MsgBox(0, "Friend", "Success")

$sExpColour = StringReplace(StringStripCR(FileRead("colour.txt"), @LF, "|")
If StringRegExp($sText, "(?i)(?m:^)" & $sExpColour & "\s*is\smy\sfriend")  Then MsgBox(0, "Color", "Success")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thank so much GEOSoft , code working :)

This is my code :

$sText = _IEBodyReadText ($oIE)

$library_friend = StringReplace(StringStripCR(FileRead("library\library_friend.txt")), @LF, "|")
$library_friends = StringReplace(StringStripCR(FileRead("library\library_friends.txt")), @LF, "|")



Select

Case StringRegExp($sText, "Hello, "& $library_friend &" is "& $library_friends & " of MINE")
Msgbox (48, "Notice","Yes, that's true. OF MINE" ,5)

Case StringRegExp($sText, "Hello, "& $library_friend &" is "& $library_friends & " of THEM")
Msgbox (48, "Notice","Yes, that's true. OF THEM" ,5)

EndSelect

Content of Friend.txt :

Peter
Daisy
Tommy
Luxi
Frank

Content of Friend.txt :

friend
a friend
the best friend
old friend
new friend

When the code read form $oIE : "Hello, Peter is the best friend of MINE"

Box --> "Yes, that's true. OF MINE"

When the code read form $oIE : "Hello, Peter is the best friend of THEM"

Box --> "Yes, that's true. OF MINE" -----> Why MINE ??? The Question is THEM, but the code wrire MINE.

I dont understand @_@

Share this post


Link to post
Share on other sites

Did I use a Select statement in my example? I left that out for a reason; because it will stop at the first match. Also that expression you used hardly resembles what I gave you. Do we need case sensitivity? Are there any extra characters including spaces that will have to match? How many times are each of those strings going to appear in a page?

You didn't provide any example of what we are searching through to find the correct responses. And without seeing that I can't come up with a guaranteed working expression.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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