none
How to replace char by char RRS feed

  • Question

  • I want to replace each character in file with another one.

    Now I'm imlementing it by using Find.Execute() method, but in this case it spends time for searching and then replaces it, then search for another character from the begining of file again, so if I want to replace all the alphabetic letters it will go through the whole document 26 x2 (lower case and upper case) =48 times, but I want it to replace by 1 lookup, so like: It get the first character it is "a" replace with " a' ", if the next char is "c" replace with "s" etc, make it by one look up, so it goes through the whole document only one time.

    I know I can implement it just by writing my own code, but I'm wondering may be there is some built-in class that  can ease my life :)

    any advice will be apreciated, thank you

    Saturday, January 19, 2013 1:40 PM

Answers

  • Nothing built-in for this purpose, I'm afraid.

    "Walking" the characters in a document will also be a fairly slow process. Best performance can probably be achieved by working directly with the XML that makes up the file, outside the Word application process...


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, January 19, 2013 3:14 PM
    Moderator

All replies

  • Nothing built-in for this purpose, I'm afraid.

    "Walking" the characters in a document will also be a fairly slow process. Best performance can probably be achieved by working directly with the XML that makes up the file, outside the Word application process...


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, January 19, 2013 3:14 PM
    Moderator
  • If you don't know what XML is, then the learning curve would be much too steep - better to stick with VBA.

    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, January 19, 2013 5:56 PM
    Moderator