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.
Remarks
Up to PB6.30 there was a #PB_String_InPlace 'Mode' for in-place replacing, which isn't supported anymore. For more informations see the Migration from PureBasic 6.30 to 6.40 guide.
Example
Debug ReplaceString("This is Art", " is", " was") ; Will display "This was Art"
test$ = "Hello again, hello again"
Result$ = ReplaceString(test$, "HELLO", "oh no...", #PB_String_NoCase, 10) ; Will display "Hello again, oh no... again"
Debug Result$
See Also
RemoveString(), InsertString(), FindString(), ReplaceRegularExpression()
Supported OS
All