脚本用变音符Á,É,Í,...替换字母A,E,I,

时间:2016-04-19 19:50:33

标签: vbscript

你能告诉我在这个脚本中我需要改变什么来获得这个输出吗?

“输出是Acailandia”

Function EliminarAcentos(texto)

Dim i, s1, s2
s1 = "ÁÀÉÈÍÏÓÒÚÜáàèéíïóòúüñç"
s2 = "AAEEIIOOUUaaeeiioouunc"
If Len(texto) <> 0 Then
    For i = 1 To Len(s1)
        texto = Replace(texto, Mid(s1,i,1), Mid(s2,i,1))
    Next
End If

EliminarAcentos = texto

End Function

C:GT; cscriptscript1Açailândia

1 个答案:

答案 0 :(得分:2)

如果您幸运(脚本和控制台的可比代码页/编码),请添加

  1. â到s1和a到s2
  2. “输出是”到命令行
  3. 会给你:

    cscript 36728122.vbs "The output is Açailândia"
    The output is Acailandia
    

    更新评论:

    主要代码:

    WScript.Echo EliminarAcentos(WScript.Arguments(0))
    

    完整代码:

    Option Explicit
    
    Function EliminarAcentos(texto)
        Dim i, s1, s2
        s1 = "ÁÀÉÈÍÏÓÒÚÜáàèéíïóòúüñçâ"
        s2 = "AAEEIIOOUUaaeeiioouunca"
        If Len(texto) <> 0 Then
            For i = 1 To Len(s1)
                texto = Replace(texto, Mid(s1,i,1), Mid(s2,i,1))
            Next
        End If
        EliminarAcentos = texto
    End Function
    
    WScript.Echo EliminarAcentos(WScript.Arguments(0))