All docs
V20.2
20.2
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.

Text

  • 2 minutes to read

Get the whole text of the main sub-document

Related members: getText

var mainSubDocumentText = richEdit.document.getText();

Get the selected text

Related members: activeSubDocument, getText

var selectedText = richEdit.selection.activeSubDocument.getText(richEdit.selection.intervals[0]);

Get the main sub-document's content length

Related members: RichEditDocumentBase.length, main, SubDocument.length

var mainSubDocumentLength = richEdit.document.length;
//or 
var mainSubDocumentLength = richEdit.document.subDocuments.main.length;

Insert text at the cursor position

Related members: insertText(position, text), activeSubDocument, active

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
subDocument.insertText(position, 'text');

Insert text at the end of the active sub-document

Related members: insertText(position, text), activeSubDocument, active, length

var subDocument = richEdit.selection.activeSubDocument;
var position = subDocument.length - 1;
subDocument.insertText(position, 'text'); 

Insert text at the end of the main sub-document

Related members: insertText(position, text), main, length

var subDocument = richEdit.document.subDocuments.main;
subDocument.insertText(subDocument.length - 1, 'text'); 

// or
// richEdit.document.insertText(richEdit.document.length - 1, 'text');

Insert text at the start of a header

Related members: insertText(position, text), SectionCollection getHeader, getFooter, HeaderFooterType

var createHeaderIfNotExist = true;
var section = richEdit.document.sections.getByIndex(0);
var subDocument = section.getHeader(DevExpress.RichEdit.HeaderFooterType.Primary, createHeaderIfNotExist);
var position = 0;
subDocument.insertText(position, 'text');

Delete all text in the active sub-document

Related members: deleteText(interval), activeSubDocument, interval

var subDocument = richEdit.selection.activeSubDocument;
subDocument.deleteText(subDocument.interval);

Apply character properties to inserted text

Related members: setCharacterProperties(interval, characterProperties), insertText(position, text), beginUpdate, beginTransaction, activeSubDocument, active

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var characterProperties = {
    bold: true,
    fontName: richEdit.document.fonts.getByIndex(0).name,
};

richEdit.history.beginTransaction();
richEdit.beginUpdate();
var interval = subDocument.insertText(position, "text");
subDocument.setCharacterProperties(interval, characterProperties);
richEdit.endUpdate();
richEdit.history.endTransaction();

Insert mail template

Related members: insertText(position, text), insertParagraph(position), activeSubDocument, active, beginUpdate, beginTransaction, Interval, focus, setSelection(position)

var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var templateText = '[Type your text here]';

richEdit.beginUpdate();
richEdit.history.beginTransaction();

position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertParagraph(position).interval.end;
position = subDocument.insertText(position, 'Dear Mr Stanley,').end;
position = subDocument.insertParagraph(position).interval.end;
var tmpTextInterval = subDocument.insertText(position, templateText);
position = tmpTextInterval.end;
position = subDocument.insertParagraph(position).interval.end;

richEdit.endUpdate();
richEdit.history.endTransaction();

richEdit.selection.setSelection(tmpTextInterval);
richEdit.focus();