Funzione Replace

Sostituisce una stringa con un'altra.

Sintassi:


       Replace (Expression As String, Find As String, Replace As String [, Start = 1 [, Count = -1 [, Compare = True]]]) As String
    

When needing to pass less parameters, use keywords arguments. Passing values for fewer parameters by position requires to supply values for all parameters before them, optional or not. This ensures that the values are in the correct positions. If you pass the parameters by name - using keyword arguments - you may omit all other intermediate arguments.

Valore restituito:

String

Parametri:

Expression: Any string expression that you want to modify.

Find: Any string expression that shall be searched for.

Replace: Any string expression that shall replace the found search string.

Start: espressione numerica opzionale che indica la posizione del carattere da cui iniziare la ricerca e anche l'inizio della parte di stringa da restituire.

Count: Optional maximum number of times the replace shall be performed. When set to -1, all possible replacements are performed.

Compare: espressione logica facoltativa che definisce il tipo di confronto. Il valore di questo parametro può essere True (vero) o False (falso). Il valore predefinito True specifica un confronto non sensibile alle maiuscole; il valore False specifica un confronto di tipo binario sensibile alle maiuscole. Potete usare anche 0 al posto di False o o 1 al posto di True.

Codici di errore:

5 Richiamo di procedura non valido

Esempio:


        MsgBox Replace ("aBbcnnbnn", "b", "$", 1, 1, False)'restituisce "aB$cnnbnn"
        REM significato: "b" deve essere sostituito, ma
        REM * only when lowercase (compare=False), hence second occurrence of "b"
        REM * only first (respecting case) occurrence (count=1)
        MsgBox Replace ("ABCDEFGHI", "E", "*", 4)
        REM restituisce D*FGHI perché la ricerca inizia dalla posizione 4, che è anche l'inizio della stringa restituita.
        MsgBox Replace("aBbcnnbnn", "b", "$£", compare:=False)  'returns "aB$£cnn$£nn"
        REM Replace all (count = -1) "b" with "$£" respecting casing (compare=False) starting from first letter (start=1)