在网上找了一个,可能System中没有包含Character这个类,所以,没注意了。
求各位帮忙看一眼。谢谢。
求各位帮忙看一眼。谢谢。
解决方案 »
- 把asp Rewrite到aspx失败
- 调用一个web服务,它返回的是一张图片,我该使用什么控件把这张图显示在我的winform里面?
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (prov
- SQL语句 列 定长度显示
- 请教关于ASP.NET,AJAX的问题
- 关于.NET在2003的权限问题
- DataList 的 EditItemTemplate 使用遇到问题,急用,散分
- 如何在一个 OleDbCommand 对象中多次执行SQL语句
- 请教,C#的ASP程序可以启动windows程序么?
- 博客列表和相册的实现?
- 没分了,不好意思哈,帮忙.为什么js调用控件的ID变了名字
- ADO.net连接oracle问题
则统计+1 最后输出统计变量。
var query = from x in s.ToUpper() group x by x >= 'A' && x <= 'Z' ? 0 : (x >= '0' && x <= '9' ? 1 : 2) into g select new { type = g.Key, count = g.Count() };
Console.WriteLine("字母有{0}个", query.Where(x => x.Type == 0).Single().count);
Console.WriteLine("数字有{0}个", query.Where(x => x.Type == 1).Single().count);
Console.WriteLine("其它有{0}个", query.Where(x => x.Type == 2).Single().count);
string test = "abCdef12tf356我们都是7";
int count1 = Regex.Matches(test,@"\d").Count;// 数字个数:6
int count2 = Regex.Matches(test, @"(?i)[a-z]").Count;//字母个数:8
int count3 = Regex.Matches(test, @"[\u4e00-\u9fa5]").Count;//汉字个数:4
string str = "另顶戴枯aslkdfjasf345sdfa"; char[] arr = str.ToCharArray(); int number = 0;
int english = 0; foreach (char c in arr)
{
int i = c + 0; if (i > 47 && i < 58)
number++;
else if ((i > 64 && i < 91) || (i > 96 && i < 123))
english++;
} Console.WriteLine(string.Format("原字符串:{0}\r\n数字:{1} 个\r\n字母:{2} 个", str, number, english)); Console.Write("\n按任一键结束...");
Console.ReadKey();
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "hello csdn, hello 404.";
var query = from x in s.ToUpper() group x by x >= 'A' && x <= 'Z' ? 0 : (x >= '0' && x <= '9' ? 1 : 2) into g select new { type = g.Key, count = g.Count() };
Console.WriteLine("字母有{0}个.", query.Where(x => x.type == 0).Single().count);
Console.WriteLine("数字有{0}个.", query.Where(x => x.type == 1).Single().count);
Console.WriteLine("其它有{0}个.", query.Where(x => x.type == 2).Single().count);
}
}
}字母有14个.
数字有3个.
其它有5个.
Press any key to continue . . .
用的一楼方法,结果没有问题 //i1字母数量、i2数字数量、i3其它
int i1=0, i2=0, i3=0;
string temp = "abcdefghij852为什么417";
foreach (char item in temp)
{
int i = (int)item;
if (i > 47 && i < 58)
i2++;
else if ((i > 96 && i < 123) || (i > 64 && i < 91))
i1++;
else
i3++;
}
string result = string.Format("字母数量:{0},数字数量:{1},文字数量:{2}",i1,i2,i3);
Console.WriteLine(result);
Console.ReadLine();
string str = "1ah234b100A";
Regex regex = new Regex("[0-9]");
Console.WriteLine(regex.Matches(str).Count);
Console.WriteLine("-----------------------");
regex = new Regex("[a-z,A-Z]");
Console.WriteLine(regex.Matches(str).Count);