ms word - Correlate Range.Text to Range.Start and Range.End -


i'm using regular expressions search against plain text returned following property:

namespace microsoft.office.interop.word {     public class range     {         ...         public string text { get; set; }         ...     } } 

based upon matches want make changes formatted text corresponds plain text. problem have indices of characters in .text property not match .start , .end properties of range object. know way match these indices up?

(i can't use word wildcard find capabilities (as replacement .net regular expressions) because aren't powerful enough patterns i'm searching (non-greedy operators etc.))

i can move correct number of characters starting document.range().collapse(wdcollapsestart)and range.movestart(wdunitchar, match.index) since moving characters matches formatted text position matches in plain text.

my problem i'm 4 characters far along in formatted text...so maybe has other story ranges? i'm not sure...

apparently reason matches still off had hidden "bell" characters (char bell = '\a';). replacing these empty string inside application.activedocument.range().text, matches on property match correctly range achieved by:

word.range range = activedocument.range(); range.collapse(word.wdcollapsestart); range.movestart(word.wdunits.character, regexmatch.index); 

basically can mirror indexes in .text property moving through formatted text character-by-character. caveat need remove strange characters such bell character .text property.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -