public void OxidationNumbers(string scase) { if (_doc == null) return; else if (string.IsNullOrWhiteSpace(_doc.Content.Text)) return; Regex regex; MatchCollection mc; if (scase == "sc") { regex = new Regex(@"(?<roman>\b[IVXLCDM]+\b)|(?<roman>\b[ivxlcdm]+\b)"); mc=regex.Matches(_doc.Content.Text); } else if (scase == "uc") { regex = new Regex(@"(?<roman>\b[ivxlcdm]+\b)"); mc=regex.Matches(_doc.Content.Text); } else regex = new Regex(@"(?<roman>\b[IVXLCDM]+\b)"); this.captureOxidation(_doc.Content, scase, regex); if (this._doc.Footnotes.Count > 0) this.captureOxidation(this._doc.StoryRanges[Word.WdStoryType.wdFootnotesStory], scase,regex); if (this._doc.Endnotes.Count > 0) this.captureOxidation(this._doc.StoryRanges[Word.WdStoryType.wdEndnotesStory], scase, regex); } public void captureOxidation(Word.Range range,string scase,Regex regex) { string message = "Do You Want Change This Occurance"; string title = "Case Selection"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; Word.Range findRange = range.Duplicate; findRange.Collapse(Word.WdCollapseDirection.wdCollapseStart); foreach (Match match in regex.Matches(range.Text)) { findRange.Find.MatchCase = true; findRange.Find.MatchWholeWord = true; findRange.Find.Text = match.Value; if (findRange.Find.Execute2007(Forward: true, Wrap: Word.WdFindWrap.wdFindContinue, Replace: Word.WdReplace.wdReplaceNone)) { if (!findRange.InRange(range)) return; Word.Range temp = findRange.Duplicate; temp.Select(); if (temp.Font.SmallCaps==-1 && scase=="sc"){} else { DialogResult result = MessageBox.Show(message, title, buttons, MessageBoxIcon.Question); if (result == DialogResult.Yes) { switch (scase) { case "sc": temp.Case = Word.WdCharacterCase.wdLowerCase; temp.Font.SmallCaps = 1; temp.Font.AllCaps = 0; break; case "uc": temp.Case = Word.WdCharacterCase.wdUpperCase; temp.Font.SmallCaps = 0; temp.Font.AllCaps = 0; break; case "lc": temp.Case = Word.WdCharacterCase.wdLowerCase; temp.Font.SmallCaps = 0; temp.Font.AllCaps = 0; break; } } } findRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)