RichText.Replace

Replace(char, char)

Replaces all occurrences of a specified Unicode character in this instance with another specified Unicode character.

public RichText Replace(char oldChar, char newChar)
ParameterTypeDescription
oldCharCharThe old char.
newCharCharThe new char.

Return Value

The RichText.

See Also


Replace(string, string)

Replaces all occurrences of a specified string in the current instance with another specified string.

public RichText Replace(string oldValue, string newValue)
ParameterTypeDescription
oldValueStringThe old value.
newValueStringThe new value.

Return Value

The RichText.

Exceptions

exceptioncondition
ArgumentNullException
ArgumentException

Examples

Shows how to pass through page’s text and make a replacement.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Text();

Dictionary<string, string> replacements = new Dictionary<string, string>();
replacements.Add("voice over", "voice over new text");

// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");

IList<Page> pageNodes = oneFile.GetChildNodes<Page>();

// Get all RichText nodes
IList<RichText> textNodes = pageNodes[0].GetChildNodes<RichText>();

foreach (RichText richText in textNodes)
{
    foreach (KeyValuePair<string, string> kvp in replacements)
    {
        // Replace text of a shape
        richText.Replace(kvp.Key, kvp.Value);
    }
}

// Save to any supported file format
dataDir = dataDir + "ReplaceTextOnParticularPage_out.pdf";
oneFile.Save(dataDir, SaveFormat.Pdf);

Shows how to generate a new document by replacing special text pieces in a template.

string dataDir = RunExamples.GetDataDir_Text();

var D = new Dictionary<string, string>
            {
                { "Company", "Atlas Shrugged Ltd" },
                { "CandidateName", "John Galt" },
                { "JobTitle", "Chief Entrepreneur Officer" },
                { "Department", "Sales" },
                { "Salary", "123456 USD" },
                { "Vacation", "30" },
                { "StartDate", "29 Feb 2024" },
                { "YourName", "Ayn Rand" }
            };

// Load the template document into Aspose.Note.
var d = new Document(Path.Combine(dataDir, "JobOffer.one"));

// Let's replace all template words
foreach (var e in d.GetChildNodes<RichText>())
{
    foreach (var replace in D)
    {
        e.Replace($"${{{replace.Key}}}", replace.Value);
    }
}

d.Save(Path.Combine(dataDir, "JobOffer_out.one"));

See Also


Replace(string, string, TextStyle)

Replaces all occurrences of a specified string in the current instance with another specified string in specified style.

public RichText Replace(string oldValue, string newValue, TextStyle style)
ParameterTypeDescription
oldValueStringThe old value.
newValueStringThe new value.
styleTextStyleThe style of the new value.

Return Value

The RichText.

Exceptions

exceptioncondition
ArgumentNullException
ArgumentException

See Also