Jump to content

selective reader then writer


Recommended Posts

ok, what I'm trying to do is write a program that will see a specific text like "it's a beautiful day"

and if it reads that will write "let's go outside"

I have FileReadLine down for reading the text

but I'm having trouble with the IF text is "it's a beautiful day" then send text "let's go outside" part

Link to comment
Share on other sites

StringCompare

Compares two strings with options.

StringCompare ( "string1", "string2" [, casesense] )

Return Value

0 string1 and string2 are equal

> 0 string1 is greater than string2

< 0 string1 is less than string2

Example

$result = StringCompare("MELÓN", "melón")

MsgBox(0, "StringCompare Result (mode 0):", $result)

$result = StringCompare("MELÓN", "melón", 1)

MsgBox(0, "StringCompare Result (mode 1):", $result)

$result = StringCompare("MELÓN", "melón", 2)

MsgBox(0, "StringCompare Result (mode 2):", $result)

Link to comment
Share on other sites

my code is very light cause I'm not sure how to proceed with the fundamentals, and the fundemental part is that when autoit copies text when it says readfileline, how can it search for specific text within the text it's just read?

for example

say it copy's "AutoIt Forums > AutoIt v3 > General Help and Support > selective reader then writer"

how can I tell auto it to seach for specificly "General Help and Support" within that text?

I'm sure from that point I can send specific key strokes where I want them, but it's that first part of if said text is found then do this that's got me stumped?

Link to comment
Share on other sites

arminius

This?

$string = "my code is very light cause I'm not sure how to proceed" & @LF & _
          "AutoIt Forums > AutoIt v3 > General Help and Support > selective reader then writer" & @LF & _
          "with the fundamentals, and the fundemental part is that when autoit"
          
$aRead = StringRegExp($string, "(?i)(General Help and Support)", 1)
If @error Then
    MsgBox(64, "Message", "Required string not found!")
    Exit
EndIf

ConsoleWrite("---> Search result: " & $aRead[0] & @LF)
Edited by rasim
Link to comment
Share on other sites

arminius

This?

$string = "my code is very light cause I'm not sure how to proceed" & @LF & _
          "AutoIt Forums > AutoIt v3 > General Help and Support > selective reader then writer" & @LF & _
          "with the fundamentals, and the fundemental part is that when autoit"
          
$aRead = StringRegExp($string, "(?i)(General Help and Support)", 1)
If @error Then
    MsgBox(64, "Message", "Required string not found!")
    Exit
EndIf

ConsoleWrite("---> Search result: " & $aRead[0] & @LF)
I believe what he was after was a program that reads what is typed, then changes it... so if I type 'your hot' it will replace the word 'hot' with 'beautiful' or something along those lines...
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

it's alot more complicated then I'm used to

well it's close, but rather then display an error when it doesn't find what it's looking for

I was wanting it to send keystrokes when it does find what it wants?

use _ispressed() and have it say up to a certain amount of characters in memory...then

if _InString("whatever") then

send("{BS}" $AmountOfLettersInTheWord)

send("New Word")

endif

kind of simple, kind of, as long as the user doesnt keep typing it will work :) lol

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

no ReaImDown, that's not at all what I'm trying to do

I just want it to copy from a text file a line of text, if it finds something it's looking for it will send completely different text on somewhere

if it doesn't find any text it's been told to watch out for then it does nothing.

Link to comment
Share on other sites

no ReaImDown, that's not at all what I'm trying to do

I just want it to copy from a text file a line of text, if it finds something it's looking for it will send completely different text on somewhere

if it doesn't find any text it's been told to watch out for then it does nothing.

I am sorry, I misunderstood then :) I have a bad habbit of skimming articles lol,

just quickly edit Rasim's coding... and it will work fine...I will see if I can do it, after I get my girlfriend from school, that is if no1 has done it for you already, I never tried this before, but I imagine its quite simple

Edited by ReaImDown
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

I am sorry, I misunderstood then :) I have a bad habbit of skimming articles lol,

just quickly edit Rasim's coding... and it will work fine...I will see if I can do it, after I get my girlfriend from school, that is if no1 has done it for you already, I never tried this before, but I imagine its quite simple

lazy lazy people haha, heres your solution...

test.txt

I am a string
this is a nice string
this string has a nice @$$

example.au3

$file = FileOpen("test.txt", 0)
global $txt = "", $Look4 = "string"
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4)
if $result <> 0 then
$a =    StringReplace($txt,$Look4,"bitch!")
MsgBox(0, "Search result:", $a)
endif
FileClose($file)
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

I'm sorry, I thank u for trying, but I'm a newb, I'm trying to learn, I want to learn but I have no idea what that code is looking for, I put bitch! in the test.txt but it came up with nothing?

That's because the code he wrote wasn't looking for "bitch!" it was looking for "string" and will replace it with "bitch!"

$file = FileOpen("test.txt", 0)
global $txt = "", $Look4 = "string";<----- $Look4 is the string that's being searched for
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4);<----$txt is the text from the file, and $Look4 is the string to look for
if $result <> 0 then
$a =    StringReplace($txt,$Look4,"bitch!");<-----$this says replace anything in $txt/the text file, that matches $Look4 or string, and replace it with bitch!
MsgBox(0, "Search result:", $a)
endif
FileClose($file)
Link to comment
Share on other sites

That's because the code he wrote wasn't looking for "bitch!" it was looking for "string" and will replace it with "bitch!"

$file = FileOpen("test.txt", 0)
global $txt = "", $Look4 = "string";<----- $Look4 is the string that's being searched for
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4);<----$txt is the text from the file, and $Look4 is the string to look for
if $result <> 0 then
$a =    StringReplace($txt,$Look4,"bitch!");<-----$this says replace anything in $txt/the text file, that matches $Look4 or string, and replace it with bitch!
MsgBox(0, "Search result:", $a)
endif
FileClose($file)
sorry, didnt have time to sit there and comment on it, I was in a rush, girlfriend and my parents were waiting on me lol

updated code...added $ReplaceWith

$file = FileOpen("test.txt", 0)
global $txt = "", $ReplaceWith = "bitch!", $Look4 = "string";<----- $Look4 is the string that's being searched for
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    $txt = ($txt & $chars)
Wend
$result = StringInStr($txt, $Look4);<----$txt is the text from the file, and $Look4 is the string to look for
if $result <> 0 then
$a =    StringReplace($txt,$Look4,$ReplaceWith);<-----$this says replace anything in $txt/the text file, that matches $Look4 or string, and replace it with bitch!
MsgBox(0, "Search result:", $a)
endif
FileClose($file)
Edited by ReaImDown
[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

ok thanks guys :P it's still not quite what I was wanting it to do :D but I think I can experiment with what's there and get it to work :), thanks for all your help

np, give a shout back if I can be of more assistance, thought that was what you wanted though :P enjoy...gl

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...