antisocialneedinghelp Posted June 21, 2012 Share Posted June 21, 2012 Woohoo! Back again for more assistance! So. Does anyone know a way this is possible? Basically. I will have a textfile that will be.... ejkhfjkhf:jkhdkjhdkjhdedi77d38g239dg9g9 jefdhwejkhfwef8h:wejifhwejhwef wehdfwejh:ewfg287gf8723gf 323rRfef3:f39f78g39fg93f:Lfui23hf2L23fu2hfui2f:32fih 234df1ds:du19hd912398dh8dh And I wish to have an app that will read all of the text in each line, then remove EVERYTHING after the first : it comes across in it. Making the output, look like this. ejkhfjkhf: jefdhwejkhfwef8h: wehdfwejh: 323rRfef3: 234df1ds: Even if there are multiple :`s in the line of text, I just want it to leave everything before the very first marker. Anyone have a clue? <3 You have all been so helpful thus far~ It would be very lovely. Might even want to take this to a textbox input for "Keyword to split text?" and just put a : in it, or other trigger word. However that is not necessary, and can come later to be played with <3 For now. This is all I would need to finish my script. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 21, 2012 Moderators Share Posted June 21, 2012 antisocialneedinghelp,- Read the file into an array with _FileReadToArray.- Loop through the file using StringInStr to get the position of the first ":".- Use StringMid or StringLeft to get the charracters to the left of that point and reassign them to the array element.- Finally use _FileWriteToArray to rewrite the file. M23 antisocialneedinghelp 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted June 21, 2012 Share Posted June 21, 2012 Try this one-liner: FileWrite("out.txt", StringRegExpReplace(FileRead("in.txt"), "(?m)^([^:]*?)(:.*)$", "$1")) antisocialneedinghelp 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Malkey Posted June 21, 2012 Share Posted June 21, 2012 Other examples, with and without colons:- expandcollapse popupIf FileExists("in.txt") = 0 Then FileWrite("in.txt", _ "ejkhfjkhf:jkhdkjhdkjhdedi77d38g239dg9g9" & @CRLF & _ "jefdhwejkhfwef8h:wejifhwejhwef" & @CRLF & _ "wehdfwejh:ewfg287gf8723gf" & @CRLF & _ "323rRfef3:f39f78g39fg93f:Lfui23hf2L23fu2hfui2f:32fih" & @CRLF & _ "234df1ds:du19hd912398dh8dh") ConsoleWrite("------ jchd without colon.-------" & @LF) ;FileWrite("out.txt", StringRegExpReplace(FileRead("in.txt"), "(?m)^([^:]*?)(:.*)$", "$1")) ; jchd without colon. ConsoleWrite(StringRegExpReplace(FileRead("in.txt"), "(?m)^([^:]*?)(:.*)$", "$1") & @LF) ; jchd without colon. ConsoleWrite("------ Results with colon.-------" & @LF) ConsoleWrite(StringRegExpReplace(FileRead("in.txt"), "([^:]*?:).*", "$1") & @LF) ; Results with colon. ConsoleWrite("------ Results without colon.-----" & @LF) ConsoleWrite(StringRegExpReplace(FileRead("in.txt"), "(:.*)", "") & @LF) ; Without colon, results same as jchd's. FileDelete("in.txt") #cs ------ jchd without colon.------- ejkhfjkhf jefdhwejkhfwef8h wehdfwejh 323rRfef3 234df1ds ------ Results with colon.------- ejkhfjkhf: jefdhwejkhfwef8h: wehdfwejh: 323rRfef3: 234df1ds: ------ Results without colon.----- ejkhfjkhf jefdhwejkhfwef8h wehdfwejh 323rRfef3 234df1ds #ce antisocialneedinghelp 1 Link to comment Share on other sites More sharing options...
antisocialneedinghelp Posted June 22, 2012 Author Share Posted June 22, 2012 (edited) Gosh I love you guys <3 Most helpful support forum I have ever visited, every time I have my answer within a day <3 Love you all, Like`s all around! Edit: Erm >< The first script by jchd worked...but it removed linebreaks as well. So I cant identified what is what. And the second seemed to just delete everything o-o Ill poke them around abit to see if I can fix them~ But if I dont, Please post a way to <3 Edit: Fixed FileWrite("out.txt", StringRegExpReplace(FileRead("in.txt"), "(:.*)", @CRLF) & @LF) thanks the the help folks <3 Edited June 22, 2012 by antisocialneedinghelp 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