【问题标题】:Make comment code can be written in multiple lines使注释代码可以写成多行
【发布时间】:2013-12-11 03:05:19
【问题描述】:

我的代码:

string comments = @"(\<\!\-\-.+?\-\-\>)";   
MatchCollection commentMatches = Regex.Matches(rtb1.Text, comments); 

foreach (Match m in commentMatches)
{
   rtb1.SelectionStart = m.Index;
   rtb1.SelectionLength = m.Length;
   rtb1.SelectionColor = Color.Green;
}

我正在为我的学校项目开发一个 HTML 编辑器。我的问题是,注释部分不能写成多行。每当我换行时,整个注释代码都会变成黑色。我的问题你们都明白了。

【问题讨论】:

标签: c# syntax colors richtextbox


【解决方案1】:

在匹配模式时使用 RegexOptions.Singleline,如下所示:

            MatchCollection commentMatches = Regex.Matches(regxTextBox.Text, comments,RegexOptions.Singleline);

它将整个字符串视为一行并解决您的问题。

问候,

尼丁·乔希

【讨论】:

    猜你喜欢
    • 2011-04-24
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    相关资源
    最近更新 更多