...
string word = "临[page]兵[page]斗[page]者[page]皆[page]阵[page]列[page]在[page]前";
int iCount = Common.StringHelper.StringFindStringCount(words, "[page]");
Response.Write("总共有" + iCount.ToString() + "页<br>");
string[] stringSeparators = new string[] { "[page]" };
string[] words = words.Split(stringSeparators, StringSplitOptions.None);
foreach
(string s in
words)
Response.Write(s + "<br>");
...
///<summary>
///返回>1则存在重复的字符串,并返回值,如果小于等于1则不存在重复的字符串返回
///查找某一字符串 在目标字符串里出现的次数 思想:首先把目标字符串赋给一个字符串,然后把赋值后的字符串
///把源目标字符串替换成空值,这样把源字符串的总长度减去赋值后的字符后的总长度便是目标字符串的倍数,
///如果小于等于1,则不存在,如果>1则存在
///作者:佚名 (不小心给去掉了 - -! )
///</summary>
///<param
name="Enstr">源字符串</param>
///<param
name="Destr">目标字符串</param>
///<returns></returns>
public
static int
StringFindStringCount(string Enstr, string Destr){
int
result = 0;
//当源字符串为空时
if (Enstr == null || Enstr.ToString().Trim().Replace("'", "") == "")
{
result = 0;
}
else
{
//当目标字符串为空时
if (Destr == null ||
Destr.ToString().Trim().Replace("'",
"") == "")
{
result = 0;
}
else
{
//当源字符串长度小于目标字符串长度时
if (Enstr.Length < Destr.Length)
{
result = 0;
}
else
{
string str = Enstr;
str =
str.Replace(Destr, "");
int count = (Enstr.Length - str.Length);
if (count > 0)
//如果此值大于1,则说明存在重复字符串,否则不存在重复的字符串
result = count / Destr.Length;
else
result =
0;
}
}
}
return
result;
}
StringSplitOptions Enumeration
http://msdn.microsoft.com/en-us/library/system.stringsplitoptions(VS.80).aspx