3

Can you tell me what I need change in this script to get this output?

"The output is 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:> cscript script1 Açailândia

Sanford
  • 21
  • 4

1 Answers1

2

If you are lucky (comparable codepages/encodings for script and console), adding

  1. â to s1 and a to s2
  2. "The output is " to the command line

will give you:

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

Update wrt comment:

Main code:

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

Full code:

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))
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • Running the script I get no output: C:\Work>cscript acento.vbs açailândia Microsoft (R) Windows Script Host Versão 5.8 Copyright (C) 1996-2001 Microsoft Corporation. Todos os direitos reservados. – Sanford Apr 19 '16 at 20:40
  • How can I pass the word like a parameter to the script ? – Sanford Apr 19 '16 at 21:04
  • I´m doing this, without success (I don´t have an output): C:\Work>cscript eliminaracento.vbs açailândia Microsoft (R) Windows Script Host Versão 5.8 Copyright (C) 1996-2001 Microsoft Corporation. Todos os direitos reservados. – Sanford Apr 19 '16 at 22:20
  • Thanks a lot for your answer - Now I understood your answer and i´ts working fine. Best regards. – Sanford Apr 19 '16 at 22:36