shanet Posted December 22, 2010 Share Posted December 22, 2010 Hey autoit! I am trying to implement the string replace function so if a line starts with a ':', it is removed from the variable. I am reading from a file, setting the data to the variable and then removing the lines starting with ':' from that variable. How would I do this? If it was possible to use wildcards, it should be done like this: $var1 = StringReplace($var1, ":*" & @CRLF, "") However, because wildcards are not implemented, it will not work? Any way to get around this??? Thanks. shanet [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 22, 2010 Moderators Share Posted December 22, 2010 shanet,Read the file into an array with _FileReadToArray, then run through the array backwards and delete those elements which start with ":". Finally use _FileWriteFromArray to rewrite the file. Here is the deletion bit: #include <Array.au3> Global $aArray[4] = [3, "line 1", ":line 2", "line 3"] For $i = $aArray[0] To 1 Step -1 If StringLeft($aArray[$i], 1) = ":" Then _ArrayDelete($aArray, $i) $aArray[0] -= 1 EndIf Next _ArrayDisplay($aArray)It should be obvious why you need to go through the array backwards. 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...
shanet Posted December 22, 2010 Author Share Posted December 22, 2010 Finally use _FileWriteFromArray to rewrite the file. Here is the deletion bit: Im not going to write back to the file, but anyway... $array[0] should return the number of arrays, correct? [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 22, 2010 Moderators Share Posted December 22, 2010 shanet,Dog eaten your Help file? _FileReadToArray Remarks$aArray[0] will contain the number of records read into the array.Records, not arrays, mind. 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...
shanet Posted December 22, 2010 Author Share Posted December 22, 2010 (edited) Dog eaten your Help file? Maybe... So that will delete the whole line.Is it possible to only delete everything AFTER the ':' on that line? Edited December 22, 2010 by shanet [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 22, 2010 Moderators Share Posted December 22, 2010 shanet, Easy - in fact so easy I will let you work out how to do it yourself. A few hints if you get stuck: - 1. No longer any need to reverse loop through the array - 2. Once you have identified a line beginning with ":", use the Assignment operator to replace the content. 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...
shanet Posted December 22, 2010 Author Share Posted December 22, 2010 Once you have identified a line beginning with ":", use the Assignment operator to replace the content.But the thing is, the line wont necessarily START with :Oh s*** i just realised I have to change that, because EVERY LINE HAS THAT CHAR!!!! :@OK, I will figure that out later, so stringinstr should help identify a line with whatever character it will be, so if I could use StringReplace with wildcards, I could then delete to the end of the line. But StringReplace doesnt accept wildcards, so do I need to assign it to a variable using something that will accept wildcards? [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
rudi Posted December 22, 2010 Share Posted December 22, 2010 Hi. [kick in lines starting with ":" everything behind the ":"] $var1 = StringRegExpReplace($Var1,"(?i)(?s)((:)([^\r\n]*?)(\n)|(()([^\r\n]*?(\n))))",$2$4$5") Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 22, 2010 Moderators Share Posted December 22, 2010 shanet, If you want any more help, sit and think carefully for a while about exactly what you want to do. Then come back and explain it clearly with an example of the what the initial and changed file should look like. Otherwise we are wasting our time. 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...
shanet Posted December 22, 2010 Author Share Posted December 22, 2010 (edited) In the file, details.txt, I have links to webpages. (http: being the reason I needed to change the character)I want to be able to comment the contents, and in a small program have $var1 = FileRead(details.txt) I then want to delete everything between // (the new characher to replace ':') and @CRLF (including //, excluding the line break). Is that enough? Thanks Edited December 22, 2010 by shanet [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
rudi Posted December 22, 2010 Share Posted December 22, 2010 Hi.Your signature is working only on English windows.%programfiles% will be expanded to whatever it's named on THIS Windows instalation. Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
shanet Posted December 22, 2010 Author Share Posted December 22, 2010 Thanks Rudi. I tried your snippet, and it said I need to declare $2? I found $2$4$5 at the end, but I do not know what they do? [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 22, 2010 Moderators Share Posted December 22, 2010 shanet, Is that enough?It is certainly not what I asked you to provide, but this does what I understand you to want - remove everything after the "http:" in lines containing //: #include <Array.au3> ; Simulate reading the file into an array Global $aArray[4] = [3, _ "http://url_1_url_1_url_1_url_1_url_1_url_1", _ "http://url_2_url_2_url_2_url_2_url_2_url_2", _ "http://url_3_url_3_url_3_url_3_url_3_url_3"] ; Loop through the array For $i = 1 To $aArray[0] ; If there is a // in the line If StringInStr($aArray[$i], "//") Then ; Get rid of the end of the line $aArray[$i] = StringRegExpReplace($aArray[$i], "(.*)//.*", "$1") EndIf Next ; Display the result _ArrayDisplay($aArray) The SRE works like this: pattern to match: (.*) - capturing group of any number of characters //.* - non-capturing group made up of // followed by any number of characters replacement: $1 - first captured group The SRE looks for any number of characters followed by // and any number of characters. But it only captures the first group (i.e. the characters up to the //) for later use when we ask it to replace what it has matched with what is in that group. I hope that is clear - SREs are quite difficult to get to grips with, but well worth the effort. 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...
shanet Posted December 22, 2010 Author Share Posted December 22, 2010 Thanks Melba23, Not sure where you are but its 11:15 pm over here so its almost bedtime so I will try this tomorrow and let you know how it went. [font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS: %programfiles%/AutoIt3/autoit3.chm 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