正则表达式的基本用法(C#)
2012-07-01 16:14
288 查看
这里介绍以下正则表达式的基本用法,.net库提供了一个很简单的类给我们使用
这个类是 Regex,很方便。
下面是基本的用法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace 正则表达式1
{
class Program
{
static void Main(string[] args)
{
Regex reg = new Regex("the");
string str = "the pig is very foolish!!";
Match matchSet = reg.Match(str);
if (matchSet.Success)
{
Console.WriteLine("the 是在句子中的第{0}个单词", matchSet.Index); //序号从0 开始
}
else
{
Console.WriteLine("找不到the");
}
Console.Read();
}
}
}
这个类是 Regex,很方便。
下面是基本的用法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace 正则表达式1
{
class Program
{
static void Main(string[] args)
{
Regex reg = new Regex("the");
string str = "the pig is very foolish!!";
Match matchSet = reg.Match(str);
if (matchSet.Success)
{
Console.WriteLine("the 是在句子中的第{0}个单词", matchSet.Index); //序号从0 开始
}
else
{
Console.WriteLine("找不到the");
}
Console.Read();
}
}
}
相关文章推荐
- C# ArrayList 基本用法
- .NET/C#中的StringBuilder类型的基本用法
- C# PowerPoint操作的基本用法。
- C#中comboBox控件的一些基本用法小结
- C# KeyValuePair 的基本用法及结合泛型的用法
- c#中List基本用法
- 正则表达式基本用法C
- 【转帖】在C#应用程序中,对comboBox这个控件的一些基本用法
- C#中Dictionary的基本用法
- C# PowerPoint操作的基本用法
- C#中comboBox控件的一些基本用法小结
- 在C#应用程序中,对comboBox这个控件的一些基本用法
- C# 数组的基本用法
- C# PowerPoint操作的基本用法[转]
- c#中string的一些基本用法
- C#中foreach基本用法
- 正则表达式基本用法
- C# Winform TreeView 的一些基本用法
- c#中字典(Dictionary)基本用法