Skip to main content

ReplaceTextSmart

Replaces each paragraph (or text in cell) in the select with the corresponding text from an array of strings.

Syntax

expression.ReplaceTextSmart(textStrings, tab, newLine);

expression - A variable that represents a Api class.

Parameters

NameRequired/OptionalData typeDefaultDescription
textStringsRequiredstring[]An array of replacement strings.
tabOptionalstring"\t"A character which is used to specify the tab in the source text.
newLineOptionalstring"\r\n"A character which is used to specify the line break character in the source text.

Returns

boolean

Example

This example replaces text while preserving formatting and other things.

// Adds a text to the first paragraph of the document, sets the bold and italic properties to it, and replaces it with a new text preserving the text style.

// Replaces each paragraph (or text in cell) in the select with the corresponding text from an array of strings.

// How to replace the selected ApiRange object with a new text.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This is the normal text. ");
paragraph.AddText("The is bold text. ").SetBold(true);
paragraph.AddText("This is italic text.").SetItalic(true);

paragraph.GetRange().Select();
Api.ReplaceTextSmart(["This is the normal text. This bold text was smart replaced. This is italic text."]);