Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Jul 30, 2021 9:37 am

Hello,

I need to replace all occurrences of "*1" with suberscripted "*1" (see attachement)
So Duration *1 should be:

Superscripted.png


So how can I search for "*1" and replace it with its suberscripted text?

Thank you

Heinz4711
 
Posts: 20
Joined: Thu Feb 07, 2019 5:22 pm

Fri Jul 30, 2021 10:41 am

Hello,

Thanks for your inquiry.
Please refer to the following code to meet your requirement.
Code: Select all
            Document document = new Document();
            document.LoadFromFile(@"test.docx");
            TextSelection[] textSelections = document.FindAllString("*1", false, true);

            foreach (TextSelection selection in textSelections)
            {
                //Set the searched text as subscript
                //selection.GetAsOneRange().CharacterFormat.SubSuperScript = SubSuperScript.SubScript;

                //Set the searched text as SuperScript
                selection.GetAsOneRange().CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;
            }
            document.SaveToFile("result.docx", FileFormat.Docx);

If there are any other issues related to our products, just feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Aug 06, 2021 10:31 am

Hello,

Greetings from E-iceblue!
Has your issue been resolved? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc

cron