replace in field

Typecommand
DictionaryLCS
LibraryLiveCode Script
Syntax
replace <oldString> with <newString> in <fieldContainer> {preserving | replacing} styles
Summary

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

Introduced8.0
OSmac, windows, linux, ios, android
Platformsdesktop, server, mobile
Parameters
NameTypeDescription
oldString

Any expression that evaluates to a string, and specifies the text to replace.

newString

Any expression that evaluates to a string, and specifies the text to replace the oldString with.

fieldContainer

A field chunk.

Example
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.
RelatedKeyword: string, field
Glossary: command, regular expression, container
Command: find, filter, replace
Object: field
Function: replaceText
Control Structure: function
Description

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.

Tagstext processing