Search code examples
autoit

autoit - randomize text replacement with stringreplace function


So I am in need of replacing string text with autoit using stringreplace but I need to randomize the output.

An example of what I need is

Stringreplace($string, "and", {also|as well})

My ultimate goal is to randomly replace the text with the following options based on the word "and" with also or as well


Solution

  • I wrote this a long time ago.

    It will convert this

    My name is {John|Peter|Mark}! {Regards|Cheers|Get lost}!
    

    to something like this

    My name is John! Cheers!
    

    It works with line breaks also.

    Func SpintaxToTXT($TextWithSpintax)
    
    
        Dim $MSGMSG
        Dim $lines
    
        $lines = StringSplit($TextWithSpintax, @LF)
    
    
        For $z = 1 To $lines[0]
    
            If $z > 1 Then $MSGMSG &= @LF
    
    
            $d = StringSplit($lines[$z], "{}")
    
            For $i = 1 To $d[0]
    
                $MSGSplit = StringSplit($d[$i], "|")
                If @error Then
                    $MSGMSG &= $MSGSplit[1]
                    ContinueLoop
                EndIf
                $MSGMSG &= $MSGSplit[Random(1, $MSGSplit[0], 1)]
    
            Next
    
    
    
        Next
    
    
        Return $MSGMSG
    
    EndFunc   ;==>SpintaxToTXT