Jump to content

Recommended Posts

Posted
Nothing amazing but I use it all the time, I'm surprised something similar hasn't been added to the standard StringReplace.
 
I've never been any good at regular expressions, I'm sure if I was the whole example below could be done in one line
But for the simple minded like me here you go :)   Enjoy
$BIOS = _StringMultiReplace(CleanWMIC("bios", "biosversion"), "(|)|{|}", "")


Func _StringMultiReplace($zString, $zSearchString, $zReplaceString, $zDelimeter = "|")
    If $zString = "" OR $zSearchString = "" OR $zDelimeter = "" Then
        SetError(1)
        Return $zString
    EndIf

    $zArray  = StringSplit($zSearchString, $zDelimeter)
    For $i = 1 to $zArray[0]
        $zString = StringReplace($zString, $zArray[$i], $zReplaceString)
    Next
    Return $zString
EndFunc

 

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Posted

If your replacement string is separated with pipes you can just regexpreplace.  Also, no one else has CleanWMIC.

msgbox(0, '' , _StringMultiReplace("andtheversionofthebios", "and|the|of|bios", "^"))


Func _StringMultiReplace($zString, $zSearchString, $zReplaceString)
    If $zString = "" OR $zSearchString = ""  Then
        SetError(1)
        Return $zString
    EndIf

    return stringregexpreplace($zString , $zSearchString , $zReplaceString)
EndFunc

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
×
×
  • Create New...