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.

Tue May 19, 2020 7:36 am

Hello,

I use Spire.Doc and I need to replace some texts in a DOCX document.

I use this :
document.Replace(old, new, false, true);

But the texts to be replaced my contain "." and "@" characters which leads to some problems (whole word detection).
In Word I can open "Replace" Menu and set "ignore punctation" which solves the problem.

Is it posibble to set "ignore punctation" programmaticylly to true using Spire.Doc ?

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

Tue May 19, 2020 8:46 am

Hello,

Thanks for your inquiry.
Currently our Spire.Doc doesn't support ignoring punctuation characters like Microsoft Word when replacing text. And I simulated a Word file and tested your scenario but did encounter any problems. What problems did you encounter when using the replace method?
To help us better understand and investigate your issue, please provide us with your input file, you full test code and your expected output file. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue May 19, 2020 9:12 am

In the DOCX document I have the following text:

$SollwertC3H8@64012

I do this :
document.Replace("$SollwertC3H8", "0.12", false, true);

I would expect that the text is not replaced because "whole word" is set to true.
So expected result would be (no replacement of the text):
$SollwertC3H8@64012

But I get is this:
0.12@64012

Obiously the "@" defines $SollwertC3H8@64012 as two seperate words.
If ignore punction is not possible to set may a regex would be possible?

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

Tue May 19, 2020 11:02 am

Hello,

Thanks for your more information.
Our Spire.Doc supports replacing text by regex, please refer to the following code snippet. If you have further questions, please feel free to contact us.
Code: Select all
    Regex regex = new Regex(@"^(\$SollwertC3H8)$");
    document.Replace(regex, "0.12");


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue May 19, 2020 11:23 am

thank you very much, this works :)

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

Tue May 19, 2020 11:31 am

Hello,

Glad to hear that!
If you have other questions, just feel free to contact us.
Wish you all the best!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc