string str = "12333435";
统计“3”的数量返回4求代码如何写
统计“3”的数量返回4求代码如何写
解决方案 »
- 有多线程高手么,给一个多线程循环的例子或解决方案
- 简单的委托问题,请高手解答
- 如何更改窗体标题的颜色,即更改Form1.Text的颜色
- 再来2个C#小问题
- 在线求教难题:从配置文件中取出多个方法名及程序集路径,将配置文件中的一组方法挂接到程序的某个事件上。即根据配置文件中的设置动态的绑定到程序的指定的事件上
- 怎样将textbox的字符串值赋给excel表中
- 无分跪求!那位给个.Net C#项目的源码下载?
- 100分紧急求助:如何实现将TreeView自动定位到某个节点啊?
- C# 怎样实现数据分页?
- Visual Studio .NET 2003还没有正式版吗?
- 请问大家DataList能错乱循环吗?
- 数组问题,在线等!
string subStr = "3";
int len = str.Replace(subStr, "").Length / subStr.Length;
Text = len.ToString();
public int count3(int i)
{
int count = 0;
string str = i.ToString();
for (int j = 0; j < str.Length; j++)
{
if (str[j] == '3')
count++;
}
return count;
}
感觉写的不是很好,所以想问问大家,还有更简单的方法吗
public int count3(int i)
{
int Result = 0;
while (i > 0)
{
if (i % 10 == 3) Result++;
i = i / 10;
}
return Result;
}
string str = "12333435";
int num = System.Text.RegularExpressions.Regex.Matches(str, "3").Count;
string subStr = "3";
string result = str.Length - str.Replace(subStr, string.Empty).Length;
----------------
错了...copy的恶果...-_-#int result = str.Length - str.Replace(subStr, string.Empty).Length;要得到较高效率就不要用正则...不要用循环...
int i=0;
foreach(char c in str)
if (c=='3') i++;