Erlend Posted November 13, 2009 Share Posted November 13, 2009 (edited) hello i have to txt files contaning the following lines: txt 1 ---------- U:\USER.TXT TS WinStation Name: ICA-tcp#11 txt 2 ---------- U:\USER.TXT Server Location: TESTSERVER whats the simplest way to extract the content after : excample TESTSERVER thanks for any help Edited November 14, 2009 by Erlend Link to comment Share on other sites More sharing options...
Maurice Posted November 13, 2009 Share Posted November 13, 2009 I'm no genius but this works: $file = fileopen( @scriptdir & "/test.txt", 0 ) $stringarray = StringSplit( filereadline( $file, 2), ":" ) consolewrite( $stringarray[2] & @LF ) Content of test.txt: blabla Test:success! Link to comment Share on other sites More sharing options...
rudi Posted November 15, 2009 Share Posted November 15, 2009 Hi.For analyzing TXT file's content it's in general useful to read the content to an array: It's not always the final line you will have to examine.RegEx is flexible enough to do almost every possible search.See help file: Autoit -> Tutorials -> Regular Expressions, especially the test snippet at the bottom of these pages.#include <file.au3> ; for _filereadtoarray() #include <array.au3> ; for _arraydisplay() Dim $Content = "" $InFile = "C:\MyTest.txt" ; transfer file's content into an array. _FileReadToArray($InFile, $Content) ; have a look at your array. Look at element "0" holding the size of the array. _ArrayDisplay($Content) $LastLine = $Content[$Content[0]] $AfterColon = StringRegExpReplace($LastLine, "(^.*: )([A-Z]+$)", "$2") ; (^ start of string ; .* any character, as many times as possible ... ; : ) followed by "Colon<blank>" ; [A-Z] any upper case char ; + at least one occurrence ; $ <end-of-string> ; $1 first match (^.*: ) ; $2 2nd match ([A-Z]+§) MsgBox(0, "Content after final "":"" is...", '"' & $AfterColon & '"' & @CRLF)Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now