VBScript strtr function

A VBScript equivalent of PHP’s strtr

Function strtr(ByVal str, from, strTo)

    If isObject(from) Then
        Dim key
        For Each key In from
            str = Replace(str,key,from(key))


        Dim len1 : len1 = len(from)
        Dim len2 : len2 = len(strTo)

        If len1 > len2 Then
            from = Left(from,len2)
        ElseIf len2 > len1 Then
            strTo = Left(strTo,len1)
        End If

        str = Replace(str,from,strTo)
    End if

    strtr = str
End Function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the strings extension