例如:"描图,图号是B4纸张5号"中有12个字符,结果:其中有9个汉字和全角字符、3个半角字符
如何实现上述功能。

解决方案 »

  1.   

    不是已经有一帖了吗,怎么又问同样的问题string test = "描图,图号是B4纸张5号";
    int charZh = Regex.Matches(test, @"[\u4e00-\u9fa5]").Count;  //汉字个数
    int charSBC_NZh = Regex.Matches(test, @"(?![\u4e00-\u9fa5])[^\x00-\xff]").Count;  //除汉字外的全角字符个数
    int charSBC = Regex.Matches(test, @"[^\x00-\xff]").Count;  //全角字符个数
    int charASCII = Regex.Matches(test, @"[\x00-\xff]").Count;  //半角字符个数