Core Function Replace

From Sputnik Wiki
Jump to: navigation, search
Replace( <expression>, <find>, <replace>, <case-sensitive-flag>, <count> )

Contents

Description

Replace substrings within a string with other strings.

Parameters

expression

The expression to search use (as a string).

find

The substring to find.

replace

The string to replace the found substring with.

case-sensitive-flag

Optional; If higher than zero the replace will be case-insensitive.

Default case sensitive.

count

Optional; The number of times to replace.

1 = Replace only ONCE.

Default -1 (Replace all).

Return Value

Returns the new string, the number of replacements performed is stored in @extended.

Example

$a = "The quick brown Fox jump jump jump jump";
println(     Replace($a, "fox", "Cat")     ); // Will fail since case sensitive
println(     Replace($a, "fox", "Cat", 1)     ); // Will work
println(     Replace($a, "Fox", "Cat")     ); // Will work
println(     Replace($a, "jump", "fly", 1, 2)     ); // Will work (Replaces only 2 found matches)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox