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) #PB_String_InPlace: In-place replacing. This means that the string is replaced directly in the memory. The 'StringToFind$' and 'ReplacementString$' parameter must have the same length. This is a dangerous option, for advanced users only. The advantage is the very high speed of the replacement. When using this option, the result of ReplaceString() has to be ignored (and not affected to something, as this is the string passed in parameter which is changed).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 (see the #PB_String_InPlace mode for a different behavior).
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