Onetastic Macro Documentation >
>
>
String_Replace String_Replace
Finds occurences of a search string in the given string and replaces them with a replacement string and returns the resulting string.
Syntax
String String_Replace(
String string,
Mixed search,
Mixed replacement,
Bool ignorecase,
out Numeric count)
Parameters
- String string
- String being searched and replaced on.
- Mixed search
- The value being searched for. This can be a single string or an array of strings. If it is a single string, replacement should also be a single string and, each occurence of that string is replaced with the replacement string. If it is an array of strings each value is replaced starting from the first element in the array. The replacement can be a single string or an array of strings in this case.
- Mixed replacement
- The value to replace the search string. This can be a single string or an array of strings. If it is a single string, each occurence of the search string or strings is replaced with the replacement string. If it is an array of strings each value in the array of search strings is replaced with the corresponding entry in the replacement array.
- Bool ignorecase
- Ignores the case of the search string(s) if set to true.
- out Numeric count
- The number of replacements performed will be stored in this variable.
Examples
$string = "abcdefghijABCDEFGHIJ"
String_Replace($string, "345", "{}", true, $count)
String_Replace($string, "def", "{}", true, $count)
String_Replace($string, "def", "{}", false, $count)
String_Replace($string, Array("a", "d", "H"), "{}", true, $count)
String_Replace($string, Array("a", "}b", ")c"), Array("{}", "()", "[]"), true, $count)
String_Replace($string, Array("ab", "xy", "jA"), Array("XY", "ZW"), false, $count)
String_Replace($string, "ab", Array("XY", "ZW"), true, $count)
|