如何解决此错误“字符串参数太长。” [英] How to solve this error "String parameter too long."

查看:245
本文介绍了如何解决此错误“字符串参数太长。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用正则表达式选择单词内容,当选择单词内容时,它显示字符串参数太长。问题是什么

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

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







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

推荐答案

1 ^ |


2;
}
}
t.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
}
}
}
2"; } } t.Collapse(Word.WdCollapseDirection.wdCollapseEnd); } } }


为了将来参考,当您收到错误时,请指定哪行代码导致错误。



您收到的错误消息应该非常清楚,您使用的方法不能像您尝试的那样使用字符串。



简单的谷歌搜索错误为您提供了如何解决这个问题的选项。



例如:http://stackoverflow.com/questions/5050902/runtime-error-5854-string-parameter-is-too - 长 [ ^ ]
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[^]


这篇关于如何解决此错误“字符串参数太长。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆