c#:定位元字符^ $

^ 匹配出现在字符串的开头或者行的开头

$匹配出现在字符串的结尾或者行的结尾

static void Main(string[] args)
{
  string s="I am blue cat.";
  string res=Regex.Replace(s,"^","开始:");
  console.writeline(res);

}

 的结果为开始:I am blue cat.

   同理Regex.Replace(s,"$","结束")

   结果为I am blue cat.结束 

posted @ 2020-05-27 19:50  江小明Moon  阅读(509)  评论(0编辑  收藏  举报