Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Program.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Novacode;
  6. using System.Text.RegularExpressions;
  7. using System.IO;
  8. using System.Xml.Linq;
  9. namespace StringReplaceTestApp
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. File.Copy(@"Test.docx", "Manipulated.docx", true);
  16. // Load the document that you want to manipulate
  17. DocX document = DocX.Load(@"Manipulated.docx");
  18. // Loop through the paragraphs in the document
  19. foreach (Paragraph p in document.Paragraphs)
  20. {
  21. /*
  22. * Replace each instance of the string pear with the string banana.
  23. * Specifying true as the third argument informs DocX to track the
  24. * changes made by this replace. The fourth argument tells DocX to
  25. * ignore case when matching the string pear.
  26. */
  27. p.Replace("pear", "banana", true, RegexOptions.IgnoreCase);
  28. }
  29. // File will be saved to \StringReplaceTestApp\bin\Debug
  30. document.Save();
  31. }
  32. }
  33. }