有关html字符转换和处理的几个函数
有关html字符转换的两个函数
作者:admin 日期:2006-02-04
1
程序代码
public string Encode(string str)
{
str=str.Replace("&","&");
str=str.Replace("'","''");
str=str.Replace("\"",""");
str=str.Replace(" "," ");
str=str.Replace("<","<");
str=str.Replace(">",">");
str=str.Replace("\n","<br>");
return str;
}
2.
程序代码
public string Decode(string str)
{
str=str.Replace("\n","<br>");
str=str.Replace(">",">");
str=str.Replace("<","<");
str=str.Replace(" "," ");
str=str.Replace(""","\"");
return str;
}
单个字符分割
string s="abcdeabcdeabcde";
string[] sArray=s.Split('c');
foreach(string i in sArray)
Console.WriteLine(i.ToString());
输出下面的结果:
ab
deab
deab
de
多个字符分割
string s="abcdeabcdeabcde
string[] sArray1=s.Split(new char[3]{'c','d','e'});
foreach(string i in sArray1)
Console.WriteLine(i.ToString());
可以输出下面的结果:
ab
ab
ab
多个字符分割(正则表达式)
string content="agcsmallmacsmallgggsmallytx";
string[]resultString=Regex.Split(content,"small",RegexOptions.IgnoreCase)
foreach(string i in resultString)
Console.WriteLine(i.ToString());
输出下面的结果:agc
mac
ggg
ytx
程序代码public string Encode(string str)
{
str=str.Replace("&","&");
str=str.Replace("'","''");
str=str.Replace("\"",""");
str=str.Replace(" "," ");
str=str.Replace("<","<");
str=str.Replace(">",">");
str=str.Replace("\n","<br>");
return str;
}
2.
程序代码public string Decode(string str)
{
str=str.Replace("\n","<br>");
str=str.Replace(">",">");
str=str.Replace("<","<");
str=str.Replace(" "," ");
str=str.Replace(""","\"");
return str;
}
单个字符分割
string s="abcdeabcdeabcde";
string[] sArray=s.Split('c');
foreach(string i in sArray)
Console.WriteLine(i.ToString());
输出下面的结果:
ab
deab
deab
de
多个字符分割
string s="abcdeabcdeabcde
string[] sArray1=s.Split(new char[3]{'c','d','e'});
foreach(string i in sArray1)
Console.WriteLine(i.ToString());
可以输出下面的结果:
ab
ab
ab
多个字符分割(正则表达式)
string content="agcsmallmacsmallgggsmallytx";
string[]resultString=Regex.Split(content,"small",RegexOptions.IgnoreCase)
foreach(string i in resultString)
Console.WriteLine(i.ToString());
输出下面的结果:agc
mac
ggg
ytx
浙公网安备 33010602011771号