Skip to content

Latest commit

 

History

History
39 lines (32 loc) · 966 Bytes

replace.adoc

File metadata and controls

39 lines (32 loc) · 966 Bytes

replace()

Important

Deprecated in 5.0.

Replaced with method replace() of the string instance.

replace(string, old, new) => String

Returns the string with all the occurrences of old substring replaced with the new substring. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".

Table 1. Parameters

string

String

The string which will be processed.

old

String

Old substring to be replaced

new

String

The new substring, which would replace the old substring. Can be an empty string.

Return

Source string with substrings replaced.

Example
println(replace("one four three","four","two")); //Will print "one two three"
println(replace("abc  def"," ","")); //Will print "abcdef"