Συνάρτηση Replace

Αντικαθιστά κάποια συμβολοσειρά από μια άλλη.

Σύνταξη:


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

Όταν χρειάζεται να μεταβιβάσετε λιγότερες παραμέτρους, χρησιμοποιήστε ορίσματα λέξεων-κλειδιών. Η μεταβίβαση τιμών για λιγότερες παραμέτρους ανά θέση απαιτεί την παροχή τιμών για όλες τις παραμέτρους πριν από αυτές, προαιρετικές ή μη. Αυτό διασφαλίζει ότι οι τιμές βρίσκονται στις σωστές θέσεις. Εάν μεταβιβάσετε τις παραμέτρους κατά όνομα - χρησιμοποιώντας ορίσματα λέξεων-κλειδιών - μπορείτε να παραλείψετε όλα τα άλλα ενδιάμεσα ορίσματα.

Επιστρεφόμενη τιμή:

Συμβολοσειρά

Παράμετροι:

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: Optional numeric expression that indicates the character position where the search starts and also the start of the substring to be returned.

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

Compare: Optional boolean expression that defines the type of comparison. The value of this parameter can be True or False. The default value of True specifies a text comparison that is not case-sensitive. The value of False specifies a binary comparison that is case-sensitive. You can as well use 0 instead of False or 1 instead of True.

Κωδικοί σφάλματος:

5 Άκυρη κλήση διαδικασίας

Παράδειγμα:


        MsgBox Replace ("aBbcnnbnn", "b", "$", 1, 1, False)  'returns "aB$cnnbnn"
        Σημασία REM: το "b" πρέπει να αντικατασταθεί, αλλά
        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 επιστρέφει D*FGHI επιδή η αναζήτησησ ξεκινά στη θέση 4, που είναι επίσης η αρχή της επιστρεφόμενης συμβολοσειράς.
        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)