Jump to content

Recommended Posts

Posted

Hello, It's been a long time since I've been here or done any scripting. I have a question which might sound stupid, but I can't get my head around it. I notice that there are various ways to manipulate strings, but in all the help file examples, the string is always written in the script. What if my string is in a text file or on the clipboard. Suppose I want to use a function such as StringInStr to search for a match between two strings in two different text files or search for a string declared as a variable (by variable I mean a string typed in by the user). I must be missing something very simple, or going about it in the wrong way. Could anyone explain this to me, or show a simple example to illustrate something similar to what I have described. Thanks.

Czardas.

  • Developers
Posted (edited)

Hello, It's been a long time since I've been here or done any scripting. I have a question which might sound stupid, but I can't get my head around it. I notice that there are various ways to manipulate strings, but in all the help file examples, the string is always written in the script. What if my string is in a text file or on the clipboard. Suppose I want to use a function such as StringInStr to search for a match between two strings in two different text files or search for a string declared as a variable (by variable I mean a string typed in by the user). I must be missing something very simple, or going about it in the wrong way. Could anyone explain this to me, or show a simple example to illustrate something similar to what I have described. Thanks.

Czardas.

If you want to use the information from a file, you will have to read it into a Variable to be able to test/manipulate it. FileRead()

Informantion from the clipboard can be retrieved into a variable with ClipGet().

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

A tough request. How about show some code of attempt with string handling and perhaps we can explain how you are going wrong. Commenting code will help with your understanding with string handling and help us to help you.

:whistle:

Edited by MHz
Posted

A tough request. How about show some code of attempt with string handling and perhaps we can explain how you are going wrong. Commenting code will help with your understanding with string handling and help us to help you.

:whistle:

Ok, heres something to illustrate where I'm going wrong. Here is the problem: $result = StringInStr($line, "ring"). But I don't know how to combine FileReadLine with StringInStr functions.

$file = FileOpen("test.txt", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
Wend

$result = StringInStr($line, "ring")
MsgBox(0, "Search result:", $result)

FileClose($file)
Posted (edited)

Thanks. I added 3 lines to your code to find the string and show if found.

$file = FileOpen("test.txt", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringInStr($line, 'ring') Then
        MsgBox(0, '', 'We found the string "ring"')
    EndIf
Wend

$result = StringInStr($line, "ring")
MsgBox(0, "Search result:", $result)

FileClose($file)

If <condition> Then

Do someting

EndIf

The condition of StingInStr is true if the string is found so If...Then evaluates to True and proceeds until the EndIf, Else it will Not.

Edited by MHz
Posted

Thanks. That's helped a lot. After moving the final instruction into the while statement, everything seems to be working. I'll experiment for a while until I come up against the next obsticle. :whistle:

$file = FileOpen("test.txt", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringInStr($line, 'ring') Then
        MsgBox(0, '', 'We found the string "ring"')
        
    EndIf

    $result = StringInStr($line, "ring")
    MsgBox(0, "Search result:", $result)

Wend

FileClose($file)
Posted (edited)

For me, your check of $result has gone off the map so lost me there so can pnly reply with ExitLoop as you found what you want in the text file so you can excape it. Sorry, but not enough info to emphasis on to teach on any further handlljng of your script.

$file = FileOpen("test.txt", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringInStr($line, 'ring') Then
        MsgBox(0, '', 'We found the string "ring"')
        ExitLoop
    EndIf
WEnd

FileClose($file)

Edit: Bad words. I should say double up instead of off the map., Sorry.

Edited by MHz
Posted

I get it. I haven't actually started a script, I am looking for the tools I need to manipulate binary strings. Then decide on how proceed with my script. The binary part represents a piano keyboard with some of the white keys painted black (1's), and vice versa; white keys = (0's). Thanks again for your help!

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
  • Recently Browsing   0 members

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