Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the regex for select the word content, when select the word content it shows the "String parameter too long." what is the problem
C#
private void button1_Click(object sender, RibbonControlEventArgs e)
      {
          Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
          ClsTybeScript c = new ClsTybeScript(doc);
       c.applytybescript(new Regex(@"Chapter\s+(\d+)\:\s([^\n]+)", RegexOptions.IgnoreCase));                 }


C#
class ClsTybeScript
   {
        Word.Document doc = null;
        public ClsTybeScript(Word.Document doc)
        {
           this.doc = doc;
        }
        public void applytybescript(Regex regex)
        {
            Word.Range t= doc.Content.Duplicate;
                        t.Collapse(Word.WdCollapseDirection.wdCollapseStart);
                         foreach(Match match in regex.Matches(doc.Content.Text))
             {
                t.Find.ClearFormatting();
                t.Find.Text = match.Value;
                //t.Find.MatchWildcards = true;
                if (t.Find.Execute())
                {
                    if (t.InRange(doc.Content))
                    {
                        t.HighlightColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdBrightGreen;
                        t.Find.Replacement.Text = @"$1^|$2";
                    }
                }
                t.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
              }
        }
   }
Posted

1 solution

For future reference, when you get an error specify which line of code causes the error.

The error message you got should be pretty clear, the method you are using cannot take as long of a string as you are trying to do.

A simple google search of the error gives you options of how to work this out.

For example: http://stackoverflow.com/questions/5050902/runtime-error-5854-string-parameter-is-too-long[^]
 
Share this answer
 

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