Jump to content

Recommended Posts

Posted (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 ?

#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

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

  On 11/21/2013 at 3:55 PM, mikell said:

$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  
  On 11/21/2013 at 3:09 PM, Melba23 said:

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
Posted

Thornhunt,

 

  Quote

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:

  Reveal hidden contents

 

Posted

Melba,

Furthermore, did you appreciate this delightful comment - your solution looking much better than mine - while the approach is the same in both cases :D

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
  • Recently Browsing   0 members

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