Search Results for

    Show / Hide Table of Contents

    Class TextContent

    Represents a single run of text within a text content element.

    Inheritance
    System.Object
    ContentElement
    TextContent
    Implements
    ITextContentElement
    IWordTextObject
    IronSoftware.Abstractions.Word.IText
    IronSoftware.Abstractions.Word.IWordDocumentObject
    IronSoftware.Abstractions.IDocumentObject
    System.ICloneable
    IronSoftware.Abstractions.IJsonSerializable
    Inherited Members
    ContentElement.Replace(IWordDocumentObject)
    ContentElement.Remove()
    ContentElement.GetIndex<T>()
    ContentElement.Clone()
    ContentElement.CloneObject()
    ContentElement.Parent
    ContentElement.Status
    Namespace: IronWord.Models
    Assembly: IronWord.dll
    Syntax
    public class TextContent : ContentElement, ITextContentElement, IWordTextObject

    TextContent is the run of text you hold whenever you add, find, or restyle words inside a Word document. It carries the characters and the formatting that travel with them, so a single object answers both "what does this say" and "how does it look" when you build a paragraph in C#.

    A developer rarely constructs one in isolation. Paragraph.AddText and Run.AddText return a TextContent, FindText hands one back when you search, and Run accepts a params TextContent[] of them. Once you hold the object it slots into the document's element tree, ready to be appended to, split, or styled before the file is saved.

    Set the words through the Text property and the formatting through Style, which is a TextStyle covering bold, italic, color, font, and the effect stack. Convenience accessors expose the resolved formatting directly so you can read it without reaching into the style object: IsBold and IsItalic report the toggles, Color gives the fill, and Font, FontName, FontSize, and FontStyle describe the typeface. These accessors read the effective look, which is useful when you inspect a run that came back from a search rather than one you just built.

    For editing existing copy, the run carries its own methods. Append joins another run onto this one and returns the combined run, Split breaks a run on a delimiter into a List<TextContent>, Find returns the offsets where a search string occurs, and Replace swaps text in place and hands back the updated element. ToJson and ToString serialize the run for logging, diffing, or inspection while you debug a document tree.

    using IronWord.Models;
    
    var run = new TextContent("Quarterly Report");
    run.Style = new TextStyle { IsBold = true, FontSize = 18 };

    The add text how-to walks through placing runs in a document, the style text how-to applies formatting, and the replace words how-to shows find-and-replace on existing copy.

    Constructors

    TextContent()

    Initializes a new instance of the Text class.

    Declaration
    public TextContent()

    TextContent(String)

    Initializes a new instance of the Text class with the specified text content.

    Declaration
    public TextContent(string text)
    Parameters
    Type Name Description
    System.String text

    The initial text content of the Text object.

    Properties

    Color

    The color of the text.

    Declaration
    public Color Color { get; }
    Property Value
    Type Description
    System.Drawing.Color

    Font

    Declaration
    public IFont Font { get; }
    Property Value
    Type Description
    IronSoftware.Abstractions.Word.IFont

    FontName

    Declaration
    public string FontName { get; }
    Property Value
    Type Description
    System.String

    FontSize

    Declaration
    public float FontSize { get; }
    Property Value
    Type Description
    System.Single

    FontStyle

    Declaration
    public string FontStyle { get; }
    Property Value
    Type Description
    System.String

    IsBold

    Declaration
    public bool IsBold { get; }
    Property Value
    Type Description
    System.Boolean

    IsItalic

    Declaration
    public bool IsItalic { get; }
    Property Value
    Type Description
    System.Boolean

    Style

    Style for text.

    Declaration
    public TextStyle Style { get; set; }
    Property Value
    Type Description
    TextStyle

    Text

    Gets or sets the text content of the Run.

    Declaration
    public string Text { get; set; }
    Property Value
    Type Description
    System.String

    Methods

    Append(TextContent)

    Appends the text content to this Text content.

    Declaration
    public TextContent Append(TextContent textContent)
    Parameters
    Type Name Description
    TextContent textContent

    The text content to append.

    Returns
    Type Description
    TextContent

    Find(String, Nullable<RegexOptions>, Boolean, Boolean)

    Finds the indices of the specified search text within the text.

    Declaration
    public List<int> Find(string searchText, Nullable<RegexOptions> regexOption = null, bool wholeWordOnly = false, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String searchText

    The text to search for.

    System.Nullable<System.Text.RegularExpressions.RegexOptions> regexOption

    Optional. The regular expression options.

    System.Boolean wholeWordOnly

    Optional. Indicates whether to match the whole word only.

    System.Boolean caseSensitive

    Optional. Indicates whether the search is case-sensitive.

    Returns
    Type Description
    System.Collections.Generic.List<System.Int32>

    A list of indices where the search text is found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when searchText is null.

    Replace(String, String, Nullable<RegexOptions>, Boolean, Boolean)

    Finds and replaces text within this TextContentElement.

    Declaration
    public ITextContentElement Replace(string searchText, string replaceText, Nullable<RegexOptions> regexOption = null, bool wholeWordOnly = false, bool caseSensitive = false)
    Parameters
    Type Name Description
    System.String searchText

    The text to search for.

    System.String replaceText

    The text to replace with.

    System.Nullable<System.Text.RegularExpressions.RegexOptions> regexOption

    Optional regex options

    System.Boolean wholeWordOnly

    Replace whole words only

    System.Boolean caseSensitive

    Whether the search is case-sensitive

    Returns
    Type Description
    ITextContentElement

    Split(String)

    Splits the current Run into smaller Runs based on a delimiter.

    Declaration
    public List<TextContent> Split(string delimiter)
    Parameters
    Type Name Description
    System.String delimiter

    The delimiter to use for splitting.

    Returns
    Type Description
    System.Collections.Generic.List<TextContent>

    List of Run objects after split.

    ToJson()

    Declaration
    public string ToJson()
    Returns
    Type Description
    System.String

    ToString()

    Provides a textual representation of the TextContentElement.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    A string representation of the element.

    Implements

    ITextContentElement
    IWordTextObject
    IronSoftware.Abstractions.Word.IText
    IronSoftware.Abstractions.Word.IWordDocumentObject
    IronSoftware.Abstractions.IDocumentObject
    System.ICloneable
    IronSoftware.Abstractions.IJsonSerializable

    Inherited members

    Replace(IWordDocumentObject)
    Remove()
    GetIndex<T>()
    Clone()
    CloneObject()
    Parent
    Status
    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet
    IronWord_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronWord