会员
众包
新闻
博问
AI培训
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
猪
不再找借口............
博客园
首页
新随笔
联系
订阅
管理
如何:使用正则表达式搜索字符串
代码如下:
1
class
TestRegularExpressions
2
{
3
static
void
Main()
4
{
5
string
[] sentences
=
6
{
7
"
cow over the moon
"
,
8
"
Betsy the Cow
"
,
9
"
cowering in the corner
"
,
10
"
no match here
"
11
}
;
12
13
string
sPattern
=
"
cow
"
;
14
15
foreach
(
string
s
in
sentences)
16
{
17
System.Console.Write(
"
{0,24}
"
, s);
18
19
if
(System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
20
{
21
System.Console.WriteLine(
"
(match for '{0}' found)
"
, sPattern);
22
}
23
else
24
{
25
System.Console.WriteLine();
26
}
27
}
28
}
29
}
30
输出
31
cow over the moon (match
for
'
cow
'
found)
32
Betsy the Cow (match
for
'
cow
'
found)
33
cowering
in
the corner (match
for
'
cow
'
found)
34
no match here
35
posted @
2008-12-20 15:47
悟〈--觉
阅读(
285
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告