Jump to content

Extracting text


DEVVED
 Share

Recommended Posts

hmmm, so u want to get a specific text from a file alright

$Handle     =   FileOpen("YOURFILE.TXT", 0)
$string     =   FileRead($Handle)

$yourstring =   "MYSTRINGTOSEARCH"
$SString    =   StringInStr($string, $yourstring, 0)

$NewString  =   StringMid($string, $SString, StringLen($yourstring))

If $NewString = $yourstring Then
MsgBox(0, "Program Response", "The String you searched for, has been founded! result: " & $NewString)
EndIf

Exit

done

-me

Link to comment
Share on other sites

What could I use to extract specific text from a text file? I tried looking through the 'string' and 'file' commands in the AutoIt help file.

Well, you would use the 'file' and 'string' functions... :-)

Take a look at the sample script at the bottom of the page for FileRead, then look at StringInStr.

Post an example of the code that you have tried.

Edit: too late :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

@DEVVED.

This is a really greate time for you to post some code to show that you take your own questions seriously. Especially since you have asked questions alonge the same line before. Post some code and I'm sure you will get help and pointers to get it right.

Start with somthing like

Local $filename="c:\mydatafile.txt"
Local $data
$data = FileRead($filename)
; TODO: Fill in the gaps

Happy Scripting.

Link to comment
Share on other sites

I am very sorry if I am upsetting anybody on the very first forum I have ever joined. It's just that I work with alot of text files and looking for peoples different points of view on working with them. The first 3 posts I made were for a program I just finished thank's to the excellent response and experience from all of you. The last post (this one) is for another program that I am trying to put together that takes a group of text files and extracts specific string out of each one and displays it in another created text file or in a text box in a GUI so if there is a broken pattern you would see it instead of opening the original text files one by one. Again I am sorry and will limit my postings.

Link to comment
Share on other sites

I dont think that is what he meant, my impression on this forum is if u need help..Ask away!! just we all really like to have source code to look off of for reference, it makes our part of helping you 100x easier, and makes it alot easier for you considering sometimes we will actually give you a post of the corrected source you posted... :)

[sup]Psibernetic[/sup]My Creations:X-HideSecuracy

Link to comment
Share on other sites

...The last post (this one) is for another program that I am trying to put together that takes a group of text files and extracts specific string out of each one and displays it in...

Asking you to post some code also helps us understand what you are wanting to do. "Extract text" can means a few different things... with your further explanation above, I can now eliminate some of the meanings and ask...:

Is the text string of interest always in the same location in these files?

i.e. it might always be on line 12, starting at column position 5.

Or, is the text string of interest in various places in each file? ...but hopefully is preceded by some text to key off of.

Does the text string of interest only appear once in one file? If multiple times, do you want to locate (extract) all occurrences?

How large are these text files? ...a few KB or several GB?

We would need to know a bit more about the info to be displayed before suggesting a method of display. Do you want a human to find any anomaly or the script? If the script, then perhaps you would only want to display the info from the last 2 or 3 files checked and have the script halt upon finding an anomaly.

hope this helps.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I am very sorry if I am upsetting anybody on the very first forum I have ever joined. ..... Again I am sorry and will limit my postings.

No one is upset.

My point is you have to give to get. So if you give by, providing some code (we all learn form reading other peoples code), you will get code samples and opinions on how to solve your tasks. So if you want peoples view on working with text files. Describe your task. Add some code solving the task and ask if there is a better way to achieve your goal.

So finally, don't limit your posting! just follow some simple guidelines and you will give and get from the forum.

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