Livecode Wiki

Replaces text in a field container with other text with control over what happens to existing styling.Syntax:

replace <oldString> with <newString> in <fieldContainer> (preserving | replacing) styles

Examples:

replace "A" with "N" in field 1 preserving styles -- changes all As to Ns; the Ns will retain the styling of the As
replace "foo" with "bar" in char 1 to 3 of tFieldId replacing styles -- changes foo to bar in the given range of the field reference in tFieldId; the bars will have no styling.

Use the replace in field command to replace all instances of one string with another string in (part of) a field, with the choice as to whether styling is preserved or replaced.

If the preserving form is used, then the found strings will be replaced in the target field and the replacement text will take the same style as the first character in the found string.

If the replacing form is used, then the found strings will be replaced in the target field and the replacement text will have no style.

All styling outside of the instances of the pattern which are found is unaffected.

Parameters:

  • oldString (string): Any expression that evaluates to a string, and specifies the text toreplace.
  • newString (string): Any expression that evaluates to a string, and specifies the text toreplace the oldString with.
  • fieldContainer: A field chunk.

See also: function (control structure),replaceText (function),field (object),