如何从一个字符串中找到子串的个数?谢谢啦,100分在线等 我觉得你最好这样组合你的字符串string sTest = "|0|12|13|20|30|15|0|2|";这样你可以查找|0|的个数否则你需要找 0|,|0|,|0 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string sTest = "0|12|13|20|30|15|0|2|";int Count=System.Text.RegularExpressions.Regex.Matches(sTest,@"\|0\|").Count;if(sTest.Substring(0,1)=="0")Count++; string sTest = "|0|12|13|20|30|15|0|2|";MessageBox.Show(System.Text.RegularExpressions.Regex.Matches(sTest,@"\|0").Count.ToString); 用正则表达式实现:string sTest = "0|12|13|20|30|15|0|2|0";int Count = System.Text.RegularExpressions.Regex.Matches(sTest,@"(^0\|)|(\|0\|)|(\|0$)").Count;其中: ^0\| 代表 字符串开头接 0| \|0$ 代表 |0 接字符串结束 public class test : System.Web.UI.Page{ int count; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 string sTest = "0|12|13|20|30|15|0|2|"; string [] aa; aa = sTest.Split(new char[] {'|'}); for (int i=0;i<aa.Length;i++) { if (aa[i].ToString() == "0") { count +=1; } } this.Response.Write(count.ToString()); }} ^_^。我有个想法,这样可以么?string ok();string sTest = "0|12|13|20|30|15|0|2|";int i = 0;ok = sTest.split("|");foreach(string Oh in ok){ if ( Oh == "0" ) i++;}MessageBox.Show("Oh,yeah~ ,有 " & i.ToString & "个零。") 我vb.net来的,写法错了。更正一下。string ok();应该是:string ok[]; 同意wuyazhe(Love Is A Word.) string[] ok;string sTest = "0|12|13|20|30|15|0|2|";int i = 0;ok = sTest.split("|");foreach(string Oh in ok){ if ( Oh == "0" ) i++;}MessageBox.Show("Oh,yeah~ ,有 " & i.ToString & "个零。") 不熟悉c#。不好意思,又错。这次没语法错误了。这里 string[] ok; string sTest = "0|12|13|20|30|15|0|2|"; int i = 0; ok = sTest.Split('|'); foreach(string Oh in ok) { if ( Oh == "0" ) i++; } string Kao = System.Convert.ToString(i); MessageBox.Show("Oh,yeah~ ,有 " + Kao + "个零。"); string[] ok;string sTest = "0|12|13|20|30|15|0|2|";int i = 0;ok = sTest.split("|");foreach(string Oh in ok){ if ( Oh == "0" ) i++;}MessageBox.Show("Oh,yeah~ ,有 " + i.ToString + "个零。") 用这个正则式regexString = @"\|?[^0-9](0)[^0-9]\|?"; string[] ok;string sTest = "0|12|13|20|30|15|0|2|";int i = 0;ok = sTest.Split('|');foreach(string Oh in ok){ if ( Oh == "0" ) i++;}MessageBox.Show("你数数看是不是有 " + i.ToString() + " 个零。");修改了一下:) C#如何按顺序动态添加Resources文件夹里的图片? 数据库连接问题 wap版支付宝开发 关于DataSet的问题。一次用两个 100求助! 再问一次 这个问题 扫描断口的程序 如何在winform里播放realpaly和微软的流媒体视频? !!!请教高手怎样在winform中获得网关地址?!!! 无名的json怎么解析? .net做的项目怎么找包???100 DropDownList 菜鸟问题 如何立即释放系统资源?up有分
int Count=System.Text.RegularExpressions.Regex.Matches(sTest,@"\|0\|").Count;
if(sTest.Substring(0,1)=="0")Count++;
MessageBox.Show(System.Text.RegularExpressions.Regex.Matches(sTest,@"\|0").Count.ToString);
int Count = System.Text.RegularExpressions.Regex.Matches(sTest,@"(^0\|)|(\|0\|)|(\|0$)").Count;其中: ^0\| 代表 字符串开头接 0|
\|0$ 代表 |0 接字符串结束
{
int count; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string sTest = "0|12|13|20|30|15|0|2|";
string [] aa;
aa = sTest.Split(new char[] {'|'});
for (int i=0;i<aa.Length;i++)
{
if (aa[i].ToString() == "0")
{
count +=1;
}
}
this.Response.Write(count.ToString());
}
}
string ok();
string sTest = "0|12|13|20|30|15|0|2|";
int i = 0;
ok = sTest.split("|");
foreach(string Oh in ok)
{
if ( Oh == "0" ) i++;
}
MessageBox.Show("Oh,yeah~ ,有 " & i.ToString & "个零。")
string ok();
应该是:
string ok[];
string sTest = "0|12|13|20|30|15|0|2|";
int i = 0;
ok = sTest.split("|");
foreach(string Oh in ok)
{
if ( Oh == "0" ) i++;
}
MessageBox.Show("Oh,yeah~ ,有 " & i.ToString & "个零。")
string[] ok;
string sTest = "0|12|13|20|30|15|0|2|";
int i = 0;
ok = sTest.Split('|');
foreach(string Oh in ok)
{
if ( Oh == "0" ) i++;
}
string Kao = System.Convert.ToString(i);
MessageBox.Show("Oh,yeah~ ,有 " + Kao + "个零。");
string sTest = "0|12|13|20|30|15|0|2|";
int i = 0;
ok = sTest.split("|");
foreach(string Oh in ok)
{
if ( Oh == "0" ) i++;
}
MessageBox.Show("Oh,yeah~ ,有 " + i.ToString + "个零。")
regexString = @"\|?[^0-9](0)[^0-9]\|?";
string sTest = "0|12|13|20|30|15|0|2|";
int i = 0;
ok = sTest.Split('|');
foreach(string Oh in ok)
{
if ( Oh == "0" ) i++;
}
MessageBox.Show("你数数看是不是有 " + i.ToString() + " 个零。");修改了一下:)