shai Posted January 11, 2011 Share Posted January 11, 2011 i have text file like this:2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet2011-1-10 9:24:18> is a tata & time.i want remove this (2011-1-10 9:24:18> ) string from line.thanks Link to comment Share on other sites More sharing options...
computergroove Posted January 11, 2011 Share Posted January 11, 2011 I think StringTrimLeft will work $NewString = StringTrimLeft("textfile.txt",19) This should also remove the last space. Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
iamtheky Posted January 11, 2011 Share Posted January 11, 2011 Trimleft may have issues because the hour column changes from one to two digits $string = "2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet" $new = stringregexp ($string , "http://(.*)" , 1) msgbox (0, '' , 'http://' & $new[0]) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2011 Moderators Share Posted January 11, 2011 shai,StringTrimLeft will not work if the data/time has a varying number of characters: 2011-1-10 9:24:18> = 19 Chars2011-11-30 15:24:18> = 21 charsI believe you are correct to want to use a RegEx - this should work in all cases: $sText_1 = "2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet" $sURL_1 = StringRegExpReplace($sText_1, "(?i).*?> (.*)", "$1") ConsoleWrite($sURL_1 & @CRLF) $sText_2 = "2011-11-30 15:24:18> http://www.google.com/search?hl=en&safe=on&q=internet" $sURL_2 = StringRegExpReplace($sText_2, "(?i).*?> (.*)", "$1") ConsoleWrite($sURL_2 & @CRLF)Just to explain the SRE a bit:(?i) = case insensitive.*?> = A non-capturing group of the shortest run of characters ending in "> "(.*) = A capturing group of the rest of the line$1 = Replace with the first (and in this case only) capturing groupI hope all that makes sense - my brain starts to bleed when I deal with SREs. M23 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...
shai Posted January 11, 2011 Author Share Posted January 11, 2011 shai, StringTrimLeft will not work if the data/time has a varying number of characters: 2011-1-10 9:24:18> = 19 Chars 2011-11-30 15:24:18> = 21 chars I believe you are correct to want to use a RegEx - this should work in all cases: $sText_1 = "2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet" $sURL_1 = StringRegExpReplace($sText_1, "(?i).*?> (.*)", "$1") ConsoleWrite($sURL_1 & @CRLF) $sText_2 = "2011-11-30 15:24:18> http://www.google.com/search?hl=en&safe=on&q=internet" $sURL_2 = StringRegExpReplace($sText_2, "(?i).*?> (.*)", "$1") ConsoleWrite($sURL_2 & @CRLF) Just to explain the SRE a bit: (?i) = case insensitive .*?> = A non-capturing group of the shortest run of characters ending in "> " (.*) = A capturing group of the rest of the line $1 = Replace with the first (and in this case only) capturing group I hope all that makes sense - my brain starts to bleed when I deal with SREs. M23 ok its work perfect. now if i have a file in desktop the name is "list_address.txt" and in this file i have multiline like this. i want replace all lines and save the file after replaceing. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2011 Moderators Share Posted January 11, 2011 shai,Load the file into an array with _FileListToArray - loop through each line and apply the SRE - write the file back to disk with _FileWriteFromArray. Simple! But be careful: the [0] index of the array is the count, so you will need to use the $i_Base parameter when you write the file. M23 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...
GPinzone Posted January 11, 2011 Share Posted January 11, 2011 $sURL_1 = StringRegExpReplace($sText_1, "(?i).*?> (.*)", "$1") You can simplify the regex: $sURL_1 = StringRegExpReplace($sText_1, "[^>]*> ", "") [^>]*> = A non-capturing group of the longest run of characters other than ">" ending in "> " You don't need to worry about case since it will slurp up everything other than a ">" character. Gerard J. Pinzonegpinzone AT yahoo.com Link to comment Share on other sites More sharing options...
kylomas Posted January 11, 2011 Share Posted January 11, 2011 M23, I'm with ya on that "brain bleedin" thing... Do these examples assume that there are no ">"'s in the target text? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2011 Moderators Share Posted January 11, 2011 (edited) GPinzone, Thanks for that. Always happy to learn about SREs - I make no pretence of being expert at them! M23 Edit: Actually, always happy to learn about anything! Edited January 11, 2011 by Melba23 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...
Varian Posted January 11, 2011 Share Posted January 11, 2011 (edited) If you use (?m) you can parse the entire string line by line (delimited by line feeds or carriage returns) so you do not have to read the file into an arrayLocal $String = FileRead('YourFile.txt') If Not $String And Not @error Then Exit MsgBox(0, 'Before', $String) $String = StringRegExpReplace($String, '(?m)^.*> *', '') MsgBox(0, 'After', $String) Edited January 11, 2011 by Varian 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