RichText.Replace

Replace(char, char)

Sostituisce tutte le occorrenze di un carattere Unicode specificato in questa istanza con un altro carattere Unicode specificato.

public RichText Replace(char oldChar, char newChar)
ParametroTipoDescrizione
oldCharCharIl vecchio car.
newCharCharIl nuovo car.

Valore di ritorno

IlRichText .

Guarda anche


Replace(string, string)

Sostituisce tutte le occorrenze di una stringa specificata nell’istanza corrente con un’altra stringa specificata.

public RichText Replace(string oldValue, string newValue)
ParametroTipoDescrizione
oldValueStringIl vecchio valore.
newValueStringIl nuovo valore.

Valore di ritorno

IlRichText .

Eccezioni

eccezionecondizione
ArgumentNullException
ArgumentException

Esempi

Mostra come passare attraverso il testo della pagina ed effettuare una sostituzione.

// Il percorso della directory dei documenti.
string dataDir = RunExamples.GetDataDir_Text();

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

// Carica il documento in Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");

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

// Ottieni tutti i nodi RichText
IList<RichText> textNodes = pageNodes[0].GetChildNodes<RichText>();

foreach (RichText richText in textNodes)
{
    foreach (KeyValuePair<string, string> kvp in replacements)
    {
        // Sostituisci il testo di una forma
        richText.Replace(kvp.Key, kvp.Value);
    }
}

// Salva in qualsiasi formato di file supportato
dataDir = dataDir + "ReplaceTextOnParticularPage_out.pdf";
oneFile.Save(dataDir, SaveFormat.Pdf);

Mostra come generare un nuovo documento sostituendo parti di testo speciali in un modello.

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" }
            };

// Carica il documento modello in Aspose.Note.
var d = new Document(Path.Combine(dataDir, "JobOffer.one"));

// Sostituiamo tutte le parole modello
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"));

Guarda anche


Replace(string, string, TextStyle)

Sostituisce tutte le occorrenze di una stringa specificata nell’istanza corrente con un’altra stringa specificata nello stile specificato.

public RichText Replace(string oldValue, string newValue, TextStyle style)
ParametroTipoDescrizione
oldValueStringIl vecchio valore.
newValueStringIl nuovo valore.
styleTextStyleLo stile del nuovo valore.

Valore di ritorno

IlRichText .

Eccezioni

eccezionecondizione
ArgumentNullException
ArgumentException

Guarda anche