facebooktwittermenuarrow-up

GemBox Support Forum

Find & Replace only specific font characters

Hi, I want to perform find & replace on condition of a specific font. If the font name (typeface) is matched only then “find & replace” should work otherwise skip. I am using VB.NET (not C#). How this can be achieved.

Hi Maninder,

Try this:

Dim content = document.Content.Find("MyPlaceholder").FirstOrDefault(
    Function(c)
        Dim run = CType(c.Start.Parent, Run)
        Return run.CharacterFormat.FontName = "Arial"
    End Function)

If content IsNot Nothing Then content.LoadText("New Text")

Does this solve your issue?

Regards,
Mario

Sorry i could not under stand.

Example(Consider) This is the character/word to find : “word” to be replaced with “newword” if its font is set to “Arial”
The following statement should only execute if the font name of “word” is “Arial” otherwise skip it.
document.Content.Replace(“word”, “newword”)

Please provide help regd. it.

The “MyPlaceholder” is your “word”.

Anyway, try this:

For Each content In document.Content.Find("word") _
    .Where(Function(c) (CType(c.Start.Parent, Run)).CharacterFormat.FontName = "Arial") _
    .Reverse()
    content.LoadText("newword")
Next

Does this solve your issue?

Regards,
Mario