Jump to content

string replacement error


 Share

Recommended Posts

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 ?

#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 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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

  • Moderators

Thornhunt,

 

some of the keys contain multiple span tags or have the span tags first then the required data after

Then 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? :mad:

Please post a representative collection of your data that covers ALL likely instances - then you might get a useful reply. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...