using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = " /* --------------------- hello-hi ----------------------- */ ";
Regex r = new Regex("/\\* -{2,}");
if (r.IsMatch(str))
str = r.Replace(str, "");
r = new Regex("-{2,} \\*/");
if (r.IsMatch(str))
str = r.Replace(str, "");
Console.WriteLine(str.Trim());
}
}
}C#正则表达式范例replace
最新推荐文章于 2024-10-17 11:21:59 发布
本文提供了一个使用 C# 进行字符串处理的例子,展示了如何利用正则表达式去除多行注释中的破折号重复序列。通过两个 Regex 对象分别匹配开始和结束的注释标记,并将其替换为空字符串,最终输出清理后的字符串。
602

被折叠的 条评论
为什么被折叠?



