Text can be manipulated in many ways using the TX Text Control API. Depending on the current task, various classes can be used to set the input position, to retrieve the text or to set the text at the current input position.

The Basics: The Input Position

The following two properties can be used to manipulate the input position:

Both classes can be use to set the input position to a specific character index which is 0-based.

TX Text Control Input Position

Selection Class

The following code uses the Selection TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
Selection Class
The Selection class describes and handles the attributes of a text selection.
class to set the input position to the index location 3 which is the beginning of character location 4.

textControl1.Selection.Start = 3;
view raw test.cs hosted with ❤ by GitHub

The Selection class can be now used to select a range of text in order to replace it with new text.

textControl1.Selection.Start = 3;
textControl1.Selection.Length = 4;
textControl1.Selection.Text = "New Text";
view raw test.cs hosted with ❤ by GitHub

Selecting Text

Although the above code works, the Selection class should be used in a different way. The Selection TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
ServerTextControl Class
Selection Property
Gets or sets the current selection in the main text of the document.
property accepts a complete Selection object. The object can be prepared and then applied to the text as shown in the code snippet below.

textControl1.Text = "TX Text Control";
TXTextControl.Selection selection = new TXTextControl.Selection(3, 4) {
Text = "New Text"
};
textControl1.Selection = selection;
view raw test.cs hosted with ❤ by GitHub

InputPosition Class

The InputPosition TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
InputPosition Class
An instance of the InputPosition class represents the current text input position of a TXTextControl document.
constructor offers other possibilities to set the input position. This class can be used to set the input position in case the X and Y coordinates are known or a specific page, column and row number is used. The following implementations of the constructor are available:

public InputPosition(int page, int line, int column);
public InputPosition(int textPosition);
public InputPosition(int textPosition, TextFieldPosition textFieldPosition);
public InputPosition(Point location);
view raw test.cs hosted with ❤ by GitHub

To set the input position to index 3 similar to the above sample using the Selection property, the following code is required.

textControl1.InputPosition = new TXTextControl.InputPosition(3);
view raw test.cs hosted with ❤ by GitHub

Retrieving Text

In order to retrieve text from a specific range of text, the Selection class must be used. The following code shows how to retrieve the string "Text" from the above sample.

textControl1.Text = "TX Text Control";
TXTextControl.Selection selection = new TXTextControl.Selection(3, 4);
textControl1.Selection = selection;
var selectedText = selection.Text;
view raw test.cs hosted with ❤ by GitHub

To get the formatted text in any supported format, the Selection.Save TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
Selection Class
Save Method
Saves the selected text of a document with the specified format.
method can be utilized. The following code shows how retrieve the word "Text" in HTML format.

string htmlString;
textControl1.Text = "TX Text Control";
TXTextControl.Selection selection = new TXTextControl.Selection(3, 4);
textControl1.Selection = selection;
selection.Save(out htmlString, TXTextControl.StringStreamType.HTMLFormat);
view raw test.cs hosted with ❤ by GitHub

The variable htmlString contains the word "Text" in HTML format.

<?xml version="1.0" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="TX31_HTM 31.0.1101.500" name="GENERATOR" />
<title></title>
</head>
<body style="font-family:'Arial';font-size:12pt;text-align:left;">
<p lang="en-US" style="text-indent:0pt;margin-top:0pt;margin-bottom:0pt;font-size:10pt;">Text</p>
</body>
</html>
view raw test.html hosted with ❤ by GitHub

Retrieving Text without Selecting Text

Using the above methods the text must be selected to retrieve the text. The TextChar TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
TextChar Class
An instance of the TextChar class represents a single character in a Text Control document.
class can be used to retrieve a character at a specific location without setting the input position to that location. The following code returns the character "T" at index 4.

var charAtInputPos = textControl1.TextChars[4].Char;
view raw test.cs hosted with ❤ by GitHub

The Line TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
Line Class
An instance of the Line class represents a single line in a Text Control document.
class can be used to retrieve text from a specific line. The following code returns the complete text of the first line.

var lineText = textControl1.Lines[1].Text;
view raw test.cs hosted with ❤ by GitHub

The third option to retrieve text without selecting text is the usage of the Paragraph TX Text Control .NET Server for ASP.NET
TXTextControl Namespace
Paragraph Class
An instance of the Paragraph class represents a single paragraph in a Text Control document.
class that represents a complete paragraph including text and formatting. The following code returns the plain text of the complete paragraph based on input position 3.

var parText = textControl1.Paragraphs.GetItem(3).Text;
view raw test.cs hosted with ❤ by GitHub