Jump to content
Sign in to follow this  
Floppy

Replace a given string in whole HTML document

Recommended Posts

Floppy

Hello, I would like to copy and paste the text from a program into an IE istance. I made this script and it works perfectly.

#include <IE.au3>
#Include <Clipboard.au3>
#Include <String.au3>

AutoItSetOption("WinTitleMatchMode",2)
WinWaitActive(" - [s]CENSURED[/s]")
ControlFocus("","","CanvasWindowClass")
Send("^{NUMPAD5}")
Sleep(500)
Send("^c")
$oIE = _IECreate ("about:blank")
_IEPropertySet($oIE,"contenteditable",true)
_IEAction($oIE,"paste")
$sHTML = _IEBodyReadHTML($oIE)

Now I want get the text in every round brackets and replace it with another string.

For example, I have this text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. (Ciao) Duis nec elementum diam. Donec eget vehicula augue. Cras non hendrerit ligula. Proin enim augue, vulputate quis lacinia vitae, bibendum ut lectus. Integer tempor tellus a elit tristique in pellentesque mauris mattis. Duis quis mi sed urna tristique vehicula (Test). Cras molestie pretium vehicula. Pellentesque habitant morbi tristique senectus et netus et (Okay) malesuada fames ac turpis egestas. Aliquam magna dui, elementum eget euismod vitae, adipiscing ac felis. Praesent augue elit, hendrerit non adipiscing non, lacinia at velit. Integer adipiscing lectus vitae magna mattis volutpat. Aenean vel dolor eu tortor volutpat lobortis (Hello). Proin sed tortor urna, sit amet tempus erat. Mauris non dolor in urna eleifend vulputate. Praesent tempor imperdiet rutrum (Prova). Vivamus semper diam et dui ultricies facilisis. Aenean sodales luctus libero, ac vestibulum nisi sagittis sed. Vestibulum vestibulum augue eu nisl sollicitudin sed mollis tortor mollis.

And I want to replace every word in round brackets with another word.

I tried using _StringBetween($sHTML,"(",")") but I get 0 (failture).

Please help me. Thank you and bye.

Share this post


Link to post
Share on other sites
PsaltyDS

Uhmm... _StringBetween() returns an array...

#include <String.au3>
#include <Array.au3>

Global $sString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " & _
    "(Ciao) Duis nec elementum diam. Donec eget vehicula augue. " & _
    "Cras non hendrerit ligula. Proin enim augue, vulputate quis lacinia vitae, " & _
    "bibendum ut lectus. Integer tempor tellus a elit tristique in pellentesque " & _
    "mauris mattis. Duis quis mi sed urna tristique vehicula (Test). " & _
    "Cras molestie pretium vehicula. Pellentesque habitant morbi tristique " & _
    "senectus et netus et (Okay) malesuada fames ac turpis egestas. " & _
    "Aliquam magna dui, elementum eget euismod vitae, adipiscing ac felis. " & _
    "Praesent augue elit, hendrerit non adipiscing non, lacinia at velit. " & _
    "Integer adipiscing lectus vitae magna mattis volutpat. Aenean vel dolor " & _
    "eu tortor volutpat lobortis (Hello). Proin sed tortor urna, sit amet " & _
    "tempus erat. Mauris non dolor in urna eleifend vulputate. Praesent tempor " & _
    "imperdiet rutrum (Prova). Vivamus semper diam et dui ultricies facilisis. " & _
    "Aenean sodales luctus libero, ac vestibulum nisi sagittis sed. Vestibulum " & _
    "vestibulum augue eu nisl sollicitudin sed mollis tortor mollis."

$aRET = _StringBetween($sString, "(", ")")
_ArrayDisplay($aRET, "$aRET")

:blink:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Floppy

OK, thank you. I was forgetting it's an array.

Now I want to show a message for every matching word found.

For example, I have this text:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. (Ciao) Duis nec elementum diam. Donec eget vehicula augue. Cras non hendrerit ligula. Proin enim augue, vulputate quis lacinia vitae, bibendum ut lectus. Integer tempor tellus a elit tristique in pellentesque mauris mattis. Duis quis mi sed urna tristique vehicula (Test). Cras molestie pretium vehicula. Pellentesque habitant morbi tristique senectus et netus et (Okay) malesuada fames ac turpis egestas. Aliquam magna dui, elementum eget euismod vitae, adipiscing ac felis. Praesent augue elit, hendrerit non adipiscing non, lacinia at velit. Integer adipiscing lectus vitae magna mattis volutpat. Aenean vel dolor eu tortor volutpat lobortis (Ciao). Proin sed tortor urna, sit amet tempus erat. Mauris non dolor in urna eleifend vulputate. Praesent tempor imperdiet rutrum (Prova). Vivamus semper diam et dui ultricies facilisis. Aenean sodales luctus libero, ac vestibulum nisi sagittis sed. Vestibulum vestibulum augue eu nisl sollicitudin sed mollis tortor mollis.

I want to show 2 messages because there are 2 "Ciao".

I tried this but without success:

$exSEARCH=1
Do
    $sSEARCH=StringInStr($sHTML,'Ciao',1,1,$exSEARCH)
    MsgBox(0,'',$sSEARCH)
    $exSEARCH=$sSEARCH
Until $sSEARCH=0

It repeat the message endlessly.

Thank you and bye!!!

Edited by FSoft

Share this post


Link to post
Share on other sites
PsaltyDS

You already had an array, why didn't you use it?

#include <String.au3>

Global $sString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " & _
        "(Ciao) Duis nec elementum diam. Donec eget vehicula augue. " & _
        "Cras non hendrerit ligula. Proin enim augue, vulputate quis lacinia vitae, " & _
        "bibendum ut lectus. Integer tempor tellus a elit tristique in pellentesque " & _
        "mauris mattis. Duis quis mi sed urna tristique vehicula (Test). " & _
        "Cras molestie pretium vehicula. Pellentesque habitant morbi tristique " & _
        "senectus et netus et (Okay) malesuada fames ac turpis egestas. " & _
        "Aliquam magna dui, elementum eget euismod vitae, adipiscing ac felis. " & _
        "Praesent augue elit, hendrerit non adipiscing non, lacinia at velit. " & _
        "Integer adipiscing lectus vitae magna mattis volutpat. Aenean vel dolor " & _
        "eu tortor volutpat lobortis (Hello). Proin sed tortor urna, sit amet " & _
        "tempus erat. Mauris non dolor in urna eleifend vulputate. Praesent tempor " & _
        "imperdiet rutrum (Prova). Vivamus semper diam et dui ultricies facilisis. " & _
        "Aenean sodales luctus libero, ac vestibulum nisi sagittis sed. Vestibulum " & _
        "vestibulum augue eu nisl sollicitudin sed mollis tortor mollis."

$aRET = _StringBetween($sString, "(", ")")
If @error Then
    MsgBox(16, "No Matches", "No text between '()' found.")
Else
    For $n = 0 To UBound($aRET) - 1
        If $aRET[$n] = "ciao" Then MsgBox(64, "Found: " & $n, "Ciao; now go do something!")
    Next
EndIf

:blink:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  

×