VegaRise.NET
HomeDocs

Text

Text is an inline run of characters. It carries a Contentstring and an optional TextStyle, and supports Find andReplace with regex, whole-word, and case-sensitivity options.

Create and Style a Text Run

Use case: Add styled text to a paragraph.

C#
1using Vega.DOM;
2
3var text = new Text("Important Notice")
4{
5 Style = new TextStyle
6 {
7 Font = new Font
8 {
9 Latin = new FontPart { FontName = "Calibri", Size = new FontSize(12), IsBold = true },
10 Color = Color.Red,
11 },
12 BackgroundColor = Color.Yellow,
13}
14};
15
16doc.AddParagraph().AddText(text);

Find and Replace

Use case: Safely replace specific words in a run.

C#
1var text = new Text("Hello world! Welcome to the world of programming.");
2text.Replace("world", "universe");
3
4// Whole-word, case-insensitive replace
5text.Replace("hello", "Hi", wholeWordOnly: true, caseSensitive: false);

Regex-Based Replace

Use case: Replace numeric digits in a text run using a regular expression.

C#
1using System.Text.RegularExpressions;
2
3var text = new Text("Order #12345 shipped.");
4text.Replace(@"\d{5}", "*****", regexOption: RegexOptions.None);

Find All Occurrences

Use case: Get character indices where a word occurs.

C#
1var text = new Text("apple orange apple banana apple");
2var indices = text.Find("apple", caseSensitive: true);
3// indices contains 0, 13, 27

Related API

Frequently asked questions

What's the difference between Paragraph and Text?

A Paragraph is a block container; Text is an inline run that lives inside a paragraph. A paragraph can hold multiple runs with different styles.

Does Text support regular expressions?

Yes — both Find and Replace accept a RegexOptions argument.

Can I concatenate multiple styled runs into one line?

Yes. Call p.AddText(...) several times with different styles on the same paragraph.