怎样获取页面内部指定的文本内容

来源:百度知道 编辑:UC知道 时间:2024/06/01 19:06:56
比如页面内有一句话
小明:你好,吃饭了么?。我向获取冒号到句号之间的内容,怎么做
若是内容中有好几个:和句号呢?比如是这样
小明:你好,吃饭了么?。
小芳:你好,吃过饭了。
小洁:我也吃过饭了。
我想只留下他们的对话,怎么办?你刚才的方法,只能获取第一个啊
大哥,是只留下对话,对话之前的名字,也不要留啊
iceser 大哥,成功了,可以把他们的对话写入一个数组么?

string content = @"小明:你好,吃饭了么?。
小芳:你好,吃过饭了。
小洁:我也吃过饭了。";
Regex regex = new Regex( ":(?<content>[^。]*)。" );
MatchCollection matches = regex.Matches( content );
string[] results = new string[ matches.Count ];
int index = 0;
foreach ( Match m in matches )
{
results[ index++ ] = m.Groups[ "content" ].Value;
}

foreach ( string s in results )
{
Console.WriteLine( s );
}

PS:需要using using System.Text.RegularExpressions;
呵呵,把这茬儿忘写了~~

using System.Text.RegularExpressions;
用这个引用,楼上代码写的不错.

Split()
分割字符串,通过冒号。
取冒号以后的。

string a="所有内容"
string[]b=a.split(':');
for(int i=0;i<b.lenght;i++)
{
Response.Write(b[i]);
}