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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章