Contents

Roo

Text.replace_first!()

Returns a new Text object who’s value is created by replacing the first instance of the passed what text with the specified replacement text. If this Text object does not contain what then it returns a new Text object who’s value is the same as the original’s. The original text is changed to the same value as the return value.

text.replace_first!(what as Text, replace as Text) as Text

Parameters

  • what. Text object. The text you are searching for
  • replacement. Text object. The replacement text to use for the first occurrence of what

Returns

  • A new Text object. The original text is changed to the value of the returned Text object

Example

var a = "Go Go Gadget!"
var b = a.replace_first!("Go", "Yo")
print(a) # => "Yo Go Gadget!"
print(b) # => "Yo Go Gadget!"