Thornhunt Posted November 21, 2013 Posted November 21, 2013 (edited) ok i have a rather large database and i wanted to clean it up a little (remove the unneeded html) so i wipped to gether a little prog to do it for me as the database has 53000 sections alone never mind the keys for each section the script i wrote should basicly; read the string, find the text inbetween said html replace that text, then replace the said html then rewrite to the ini file EG piece of data [winnable] 1= Possible to win or achieve: <span class="illustration">a winnable election campaign; winnable games.</span> 2= capable of being won: <span class="illustration"> a winnable war.</span> string = Possible to win or achieve: <span class="illustration">a winnable election campaign; winnable games.</span> after first replace string = Possible to win or achieve: <span</span> after second replace string = Possible to win or achieve: new data [winnable] 1= Possible to win or achieve: 2= capable of being won: <span class="illustration"> a winnable war.</span> however it is returning like this [winnable] 1= 2= capable of being won: <span class="illustration"> a winnable war.</span> any chance a second pair of eyes could help me ? expandcollapse popup#include <Array.au3> #Include <String.au3> $ini = "data.ini" $secnames = IniReadSectionNames ($ini) For $i = 1 To $secnames[0] step 1 $key = IniReadSection($ini,$secnames[$i]) for $p = 1 To $key[0][0] step 1 $sb = _StringBetween($key[$p][1],'<span', '</span>') For $x = 0 to UBound($sb) - 1 step 1 $key1 = StringReplace($key,$sb[$x],"") $key2 = StringReplace($key1,"<span","") $key3 = StringReplace($key2,"</span>","") IniWrite($ini,$secnames[$i],$key[$p][0],$key3) next Next Next Edited November 21, 2013 by Thornhunt Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D
Moderators Melba23 Posted November 21, 2013 Moderators Posted November 21, 2013 Thornhunt,This seems to do the trick: #include <Array.au3> #include <String.au3> #include <Constants.au3> $ini = "data.ini" $secnames = IniReadSectionNames($ini) For $i = 1 To $secnames[0] $key = IniReadSection($ini, $secnames[$i]) For $p = 1 To $key[0][0] IniWrite($ini, $secnames[$i], $key[$p][0], StringRegExpReplace($key[$p][1], "^(.*)\s<span.*$", "$1")) Next Next $sData = FileRead($ini) MsgBox($MB_SYSTEMMODAL, "New ini", $sData)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
mikell Posted November 21, 2013 Posted November 21, 2013 $string = 'Possible to win or achieve: <span class="illustration">a winnable election campaign; winnable games.</span>' msgbox(0,"", StringLeft($string, StringInStr($string, ":")))
Thornhunt Posted November 21, 2013 Author Posted November 21, 2013 $string = 'Possible to win or achieve: a winnable election campaign; winnable games.'msgbox(0,"", StringLeft($string, StringInStr($string, ":"))) this would normally work though some of the keys contain multiple span tags or have the span tags first then the required data after. Cheers though Thornhunt,This seems to do the trick: #include #include #include $ini = "data.ini"$secnames = IniReadSectionNames($ini)For $i = 1 To $secnames[0] $key = IniReadSection($ini, $secnames[$i]) For $p = 1 To $key[0][0] IniWrite($ini, $secnames[$i], $key[$p][0], StringRegExpReplace($key[$p][1], "^(.*)\s<span.*$", "$1")) NextNext$sData = FileRead($ini)MsgBox($MB_SYSTEMMODAL, "New ini", $sData)M23 This looks promising as usual Melb, will test when I get home as I'm currently sat on a train lol. Will keep you guys updated Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D
Moderators Melba23 Posted November 21, 2013 Moderators Posted November 21, 2013 Thornhunt, some of the keys contain multiple span tags or have the span tags first then the required data afterThen what I have suggested will almost certainly not work. How many times do I have to ask that people give us ALL the required information at the beginning of a thread so that we do not waste time producing code that, although it caters for the (partially explained) problem as posted, stands no chance of being a complete solution? Please post a representative collection of your data that covers ALL likely instances - then you might get a useful reply. 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
mikell Posted November 21, 2013 Posted November 21, 2013 Melba, Furthermore, did you appreciate this delightful comment - your solution looking much better than mine - while the approach is the same in both cases
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