c#获得txt文件中字符的个数

 try
                {               
                string str = File .ReadAllText ( @"map40x10.txt" );
               // int hz = Regex .Matches ( str , @"[\u4E00-\u9FFF]" ) .Count;//汉字
               // int en = Regex .Matches ( str , "[A-Za-z]" ) .Count;
                int num = Regex .Matches ( str , @"\d" ) .Count;//数字
                int nr = Regex .Matches ( str , @"\r" ) .Count + 1;//行数
                Console .WriteLine ( "数字个数={0},行数={1}" , num , nr );
                Console .WriteLine ( str );
                }
————————————————
版权声明:本文为CSDN博主「_lessismore」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zjc_game_coder/article/details/64921398

发布了41 篇原创文章 · 获赞 13 · 访问量 9492

猜你喜欢

转载自blog.csdn.net/qq_36664772/article/details/100196188