Find and replace text in word

Dear ASPOSE team,
I was starting using you ASPOSE. WORD and I must say that I’m good impress. I write you this to help me with some scenario.
Look on text bellow, this is from my .doc file.

  • El videoclip publicitario de la Agencia tiene una duración de en seg. y será transmitido 100, <?> del que número transmitido en primer lugar durante la interrupción. <?>

I use follow code and it work great.

Document doc = new Document(@sFileName);
doc.Range.Replace("", g.sVar(reader["LCampaignName"]), false, false);

my question is: how can I find position of first <?> and last <?> and to remove all text between first<?> and last <?> Of course I can put all text in Spain in this <> and to remove it at once, this oprion Is not good because here customer can want to change text, later can use other lenaguage and is not good to make it hard code in application. So I wonder do I have other option ?

Hi

Thanks for your inquiry. You can use regular expressions to find text between tags in the document. For example see the following code:

// Open document
Document doc = new Document(@"Test001\in.doc");
// Create regular expression, which will allow us to find content between tags.
Regex regex = new Regex(Regex.Escape("<?>") + ".*" + Regex.Escape("<?>"));
// Find content in the document using this regular expression and replace it with empty string.
doc.Range.Replace(regex, string.Empty);
// Save output document.
doc.Save(@"Test001\out.doc");

Please see the following link to learn more about regular expressions:
https://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial
Hope this helps.
Best regards,

Dear ASPOSE Team
Thank you for help, it work and is already implement in real code :slight_smile:
As usual you are the best … I’m really impressed of you products and support too. And I say this because of my 10 years experience with use MANY 3 part components…
I’m interesting … what national are primary developer team ? I ask this because I almost feel spirit of object model which are very very close to what developer expect and need with 1 command, not with some complicate abstraction which very often make more mess that help. You object model is DIRECTLY what I need with almost 1 command …congratulations for this !
I’m from Bulgaria, Europe by the way.
All do all I can under the boss to buy full you package for NET. He will buy it, with sure … J

Hi

Thanks for good testimonials from your side. Most developers in Aspose.Words team are from Russia.
Best regards,