本篇内容主要讲解“C#怎么匹配以S开头的单词”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#怎么匹配以S开头的单词”吧!实例 下面的实例匹配了以 'S' 开头的单词:
本篇内容主要讲解“C#怎么匹配以S开头的单词”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“C#怎么匹配以S开头的单词”吧!
下面的实例匹配了以 'S' 开头的单词:
using System;
using System.Text.RegularExpressions;
namespace RegExApplication
{
class Program
{
private static void showMatch(string text, string expr)
{
Console.WriteLine("The Expression: " + expr);
MatchCollection mc = Regex.Matches(text, expr);
foreach (Match m in mc)
{
Console.WriteLine(m);
}
}
static void Main(string[] args)
{
string str = "A Thousand Splendid Suns";
Console.WriteLine("Matching Words that start with 'S': ");
showMatch(str, @"\bS\S*");
Console.ReadKey();
}
}
}
当上面的代码被编译和执行时,它会产生下列结果:
Matching words that start with 'S':The Expression: \bS\S*SplendidSuns
到此,相信大家对“C#怎么匹配以S开头的单词”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
--结束END--
本文标题: C#怎么匹配以S开头的单词
本文链接: https://www.lsjlt.com/news/287496.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0