Replace more characters using UDF

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Replace more characters using UDF

Post by YasserKhalil »

What do you mean with the start and end strings?
The UDF works fine with no problem at all ..

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: Replace more characters using UDF

Post by LisaGreen »

I mean have you got a string you want to change and a string that should be the result? But if you're happy then we have a result.

Lisa

YasserKhalil
PlatinumLounger
Posts: 4911
Joined: 31 Aug 2016, 09:02

Re: Replace more characters using UDF

Post by YasserKhalil »

Thank you very much Lisa for the solution. I like it and I will use it like that.
Best Regards

LisaGreen
5StarLounger
Posts: 964
Joined: 08 Nov 2012, 17:54

Re: Replace more characters using UDF

Post by LisaGreen »

Just as a taster....

VBS does not have a "Like" statement.

Here is a function to reproduce that....

Code: Select all

Public Function IsLike(ByVal Input, ByVal Pattern)
    If Input = "" Xor Pattern = "" Then
        IsLike = False
        Exit Function
    End If

    If Input = "" And Pattern = "" Then
        IsLike = True
        Exit Function
    End If

    With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "\+(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\+")
        .Pattern = "\.(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\.")
        .Pattern = "\{(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\{")
        .Pattern = "\}(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\}")
        .Pattern = "\((?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\(")
        .Pattern = "\)(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\)")
        .Pattern = "\|(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\|")
        .Pattern = "\?(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, ".")
        .Pattern = "\*(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, ".*")
        .Pattern = "#(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "\d")
        .Pattern = "\[!(?=\x5B*(?!\x5D))"
        Pattern = .Replace(Pattern, "[^")
        Pattern = "^" & Pattern & "$"
        .Pattern = Pattern
        IsLike = .Test(Input)
    End With
End Function
Lisa