c# how do I count lines in a textfile

前端 未结 7 1285
走了就别回头了
走了就别回头了 2021-02-04 13:39

any problems with doing this?

int  i = new StreamReader(\"file.txt\").ReadToEnd().Split(new char[] {\'\\n\'}).Length
相关标签:
7条回答
  • 2021-02-04 14:22

    Mayby this?

    string file = new StreamReader("YourFile.txt").ReadToEnd();
    string[] lines = file.Split('\n');
    int countOfLines = lines.GetLength(0));
    
    0 讨论(0)
提交回复
热议问题