Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in this coding I replace all roman letter terms to SMALLCAPS,CAPS CASE, LOWER CASE , the ALLCAPS value cant convert to other cases

C#
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);
              }
          }
      }
  }



In this code I select the ALLCAPS value, when execute(change from ALLCAPS to other cases) find.execute2007() not accept the allcaps value any one give solution
Posted
Comments
George Jonsson 3-Jan-15 4:22am    
You need to show part of the text you want to convert.
Also try to describe exactly what it is you want to do.
(And for me it is Saturday night, so it's time to go out and party. :) )
smksamy 3-Jan-15 4:57am    
in this problem I convert regex matches one by one in foreach loop, the selected allcaps range value [if (findRange.Find.Execute2007(Forward: true, Wrap: Word.WdFindWrap.wdFindContinue, Replace: Word.WdReplace.wdReplaceNone))
] not enter this exection statement, I don't know the problem
Andreas Gieriet 3-Jan-15 4:36am    
What is the expected behavior? I.e. which input string should result in which controlflow?
Did you try to debug?
If you get stuck with regex, make sure that your regex is correct, e.g. in a simple separate test program.
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900