ReplaceString()

Syntax

String$ = ReplaceString(String$, StringToFind$, ReplacementString$ [, Mode [, StartPosition [, NbOccurrences]]])
Description
Try to find any occurrences of 'StringToFind$' in the given 'String$' and replace them with 'ReplacementString$'.

Parameters

String$ The string to use.
StringToFind$ The string to find.
ReplacementString$ The string to use as replacement.
Mode (optional) It can be a combination of the following values:
  #PB_String_CaseSensitive : Case sensitive search (a=a) (default)
  #PB_String_NoCase : Case insensitive search (A=a)
StartPosition (optional) Specifies the character position to start the replacement. The first character position is 1. If omitted the whole string is used.
NbOccurrences (optional) Specifies how many strings should be replaced before stopping the operation. If omitted, all strings are replaced.

Return value

A new string with the replaced strings.

Example

  Debug ReplaceString("This is Art", " is", " was") ; Will display "This was Art"
  Debug ReplaceString("Hello again, hello again", "HELLO", "oh no...", 1, 10) ; Will display "Hello again, oh no... again"

  test$ = "Bundy, Barbie, Buddy"
  ReplaceString(test$, "B", "Z", 2, 1)  ; all B gets changed to Z  (directly in memory, no valid return-value here)
  Debug test$   ; Output of the changed string

See Also

RemoveString(), InsertString()

Supported OS

All

<- RemoveString() - String Index - ReverseString() ->