0

Please help me to change this code to accept a parameter in the command line

Function to remove accents - diachritics.

Function EliminarAcentos(texto)

    Dim i, s1, s2
    s1 = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜàáâãäåçèéêëìíîïòóôõöùúûü"
    s2 = "AAAAAACEEEEIIIIOOOOOUUUUaaaaaaceeeeiiiiooooouuuu"
    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

I need to run the script like this:

>remove_accents Dídímênsô
Didimenso
omegastripes
  • 12,351
  • 4
  • 45
  • 96
user2707722
  • 51
  • 2
  • 8
  • 1
    http://stackoverflow.com/questions/2806713/can-i-pass-an-argument-to-a-vbscript-vbs-file-launched-with-cscript – Saic Siquot Jun 18 '16 at 18:12
  • I put this line in the end of the script: Wscript.Arguments(0) and run the script like this: > cscript remove_acentos.vbs ênfase But I get this message; remove_acentos.vbs(1, 36) Erro de compilação do Microsoft VBScript: ')' esperado – user2707722 Jun 18 '16 at 18:21

1 Answers1

0

The error you mention in your comment ("remove_acentos.vbs(1, 36) Erro de compilação do Microsoft VBScript: ')' esperado") is not caused by the code you published.

This

Option Explicit

Function EliminarAcentos(texto)

    Dim i, s1, s2
    s1 = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜàáâãäåçèéêëìíîïòóôõöùúûü"
    s2 = "AAAAAACEEEEIIIIOOOOOUUUUaaaaaaceeeeiiiiooooouuuu"
    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

Dim texto : texto = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜàáâãäåçèéêëìíîïòóôõöùúûü"
If WScript.Arguments.Count > 0 Then texto = WScript.Arguments(0)

WScript.Echo EliminarAcentos(texto)

compiles and runs successfully - to demonstrate the use of .Arguments.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96