这两个函数分别实现了什么功能?在下不是很懂正则表达式,嘿嘿
public string Code(string chr)
{
if(chr==null)
{
return "";
}
else
{
Db List=new Db();
string Sql="select Forum_Code_Name,Forum_Code_color from Forum_Code where Isdel='0' and Forum_Code_color='#0000FF'";
SqlDataReader result = List.GetList(Sql);
while(result.Read())
{
chr = Regex.Replace(chr,"(?<x>[;/=()]{1})"+result.GetString(0)+"(?<y>[&=()]{1})",@"$1<font color='"+result.GetString(1)+"'>"+result.GetString(0)+"</font>$2",RegexOptions.IgnoreCase);
}
result.Close();
return(chr);
}
}
public string Html(string chr)
{
if(chr==null)
{
return "";
}
else
{
Db List=new Db();
string Sql="select Forum_Code_Name,Forum_Code_color from Forum_Code where Isdel='0' and Forum_Code_color<>'#0000FF'";
SqlDataReader result = List.GetList(Sql);
while(result.Read())
{
chr = Regex.Replace(chr,"(?<x>[;/]{1})"+result.GetString(0)+"(?<y>[&=]{1})",@"$1<font color='"+result.GetString(1)+"'>"+result.GetString(0)+"</font>$2",RegexOptions.IgnoreCase);
}
result.Close();
return(chr);
}
}不是很懂正则表达式,请问这两个函数分别实现了什么功能???
public string Code(string chr)
{
if(chr==null)
{
return "";
}
else
{
Db List=new Db();
string Sql="select Forum_Code_Name,Forum_Code_color from Forum_Code where Isdel='0' and Forum_Code_color='#0000FF'";
SqlDataReader result = List.GetList(Sql);
while(result.Read())
{
chr = Regex.Replace(chr,"(?<x>[;/=()]{1})"+result.GetString(0)+"(?<y>[&=()]{1})",@"$1<font color='"+result.GetString(1)+"'>"+result.GetString(0)+"</font>$2",RegexOptions.IgnoreCase);
}
result.Close();
return(chr);
}
}
public string Html(string chr)
{
if(chr==null)
{
return "";
}
else
{
Db List=new Db();
string Sql="select Forum_Code_Name,Forum_Code_color from Forum_Code where Isdel='0' and Forum_Code_color<>'#0000FF'";
SqlDataReader result = List.GetList(Sql);
while(result.Read())
{
chr = Regex.Replace(chr,"(?<x>[;/]{1})"+result.GetString(0)+"(?<y>[&=]{1})",@"$1<font color='"+result.GetString(1)+"'>"+result.GetString(0)+"</font>$2",RegexOptions.IgnoreCase);
}
result.Close();
return(chr);
}
}不是很懂正则表达式,请问这两个函数分别实现了什么功能???
我是
Regex.Replace 查这个函数的功能
RegexOptions.IgnoreCase 查这个参数的作用另外还是下断点调戏 看看chr Replace后的结果
chr = Regex.Replace(chr,"(?<x>[;/=()]{1})"+result.GetString(0)+"(?<y>[&=()]{1})",@"$1<font color='"+result.GetString(1)+"'>"+result.GetString(0)+"</font>$2",RegexOptions.IgnoreCase);
(?<x>[;/=()]{1})
[;/=()]{1}匹配一次;或/或=或(或)并捕获它到x的组里,
(?<y>[&=()]{1})匹配一次&或=或(或)
//奇怪这里的()怎么没有转义?
$1为第一个组匹配的内容
$2第二个组匹配的内容