Jump to content

help reading text


tal
 Share

Recommended Posts

hey

i try to make a script thats read from one point to another and put the text in other window

like:

<hello>

i want that all the text from the character < to the character > will display"hello"

or

<hellobye> will display "hellobye"

any idea???

please help me it's very impotent for me.

tal

Link to comment
Share on other sites

Hi

Read what and where?

A file? A web Page?

Be more specific.

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

I want it to do so

read a text file exp: untitled.txt

find the start point , a character that I decide foe example this one - "<"

and to copy all the text after this point , until he gets the End character ">"

Take all the text he read and copy them to other text file

Link to comment
Share on other sites

Clarify what is in your text file a bit.

Is it always like this?

blah blah blah blah

blah blah <this is what I want> blah blah

blah blah blah blah

Or is it sometimes like this?

blah blah blah blah

blah blah <this is

what I want> blah blah

blah blah blah blah

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

In making this little example, I found that it would work for either case.

This example assumes that you only care about the first time you see < and > in the file... and that < precedes >

$fullpath1 = @ScriptDir & "\text.txt"

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

$filetext = FileRead($file1)
$startpoint = StringInStr($filetext, "<")
$endpoint = StringInStr($filetext, ">")
$count = $endpoint - $startpoint
$text = StringMid($filetext, $startpoint + 1, $count - 1)
MsgBox(4096, "", $text)

FileClose($file1)
Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

hey thanks

it realy works :shocked:

but one more thing

if it will be like this

blah blah blah blah

blah blah [<this is what I want> blah blah <this is what I want>

blah blah blah blah

blah blah <this is what I want>blah blah blah blah

so i need it to take all the text between "<" ">" from all my text

Link to comment
Share on other sites

That would take a different approach.... let me see....

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

How about this:

; Adjust this to point to your file
$fullpath1 = @ScriptDir & "\text.txt"

; Open your file for reading
$file1 = FileOpen($fullpath1, 0)

; Check if file opened for reading OK
If $file1 = -1 Then
    MsgBox(0, "Error", "Unable to open " & $fullpath1)
    Exit
EndIf
; Make a string out of your file
$filetext = FileRead($file1)

; Close your file
FileClose($file1)

; Assign some variables for later use
$flag = 0 ; This will be tested to decide whether or not to save the info
$text = "" ; This ensures that you have a clean starting point for your output

; loop through the string you made out of your file
For $x = 1 To StringLen($filetext)
    ; Assign a variable to hold the current character in your string
    $char = StringMid($filetext, $x, 1)
    If $char = "<" Then $flag = 1
    If $char = ">" Then
        $flag = 0
        $text = $text & @CRLF
    EndIf
    If $flag = 1 And $char <> "<" Then $text = $text & $char
Next

; Display results
MsgBox(4096, "", $text)

It works well with data formatted like so:

blah blah blah blah

blah blah [<this is what I want> blah blah <this is also what I want>

blah blah blah blah

blah blah <this is another thing I want>blah blah blah blah

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

Or this:

#include <String.au3>
#include <array.au3>
$aMatches = _StringBetween( FileRead(@ScriptDir & "\text.txt")  '<', '>')
_ArrayDisplay($aMatches, 'All strings between < and >')

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

hey all

i have one more problem

now i want the same one but the start point should be a word and not a character

for example:

Hello to all this is my first script > bla bla bla bla bla bla

bla bla Hello abcdefg > bla bla bla

la bla bla hello la bla bla> la bla bla

la bla blala bla bla

the start point will be the word "hello" and the end point will be ">"

and i want it to put all the text between in a mesege box

thanks

tal

Link to comment
Share on other sites

ye

i read this but i don't know what are those commands : _StringBetween , _ArrayDisplay

i didn't found those in the help file

You don't?! :(

What version of AutoIt are you running?

Try this:

MsgBox(64, "AutoIt", "Version: " & @AutoItVersion)

The current production version is 3.2.2.0, and the Beta I have is 3.2.3.6.

:shocked:

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
Link to comment
Share on other sites

Or this:

#include <String.au3>
#include <array.au3>
$aMatches = _StringBetween( FileRead(@ScriptDir & "\text.txt")  '<', '>')
_ArrayDisplay($aMatches, 'All strings between < and >')
well i try this script with my new beta version :

#include <String.au3>

#include <array.au3>

$aMatches = _StringBetween( FileRead(@ScriptDir & "\text.txt") '<', '>')

_ArrayDisplay($aMatches, 'All strings between < and >')

and it didn't work for me

how can i display the results?

Link to comment
Share on other sites

How about (missing comma):

$aMatches = _StringBetween( FileRead(@ScriptDir & "\text.txt"),  '<', '>')

:shocked:

...and _StringBetween() works just as well in the Prod version as it does in Beta!

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
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...