Finding longest word in string

后端 未结 4 1288
醉梦人生
醉梦人生 2021-01-19 04:13

Ok, so I know that questions LIKE this have been asked a lot on here, but I can\'t seem to make solutions work. I am trying to take a string from a file and find the longest

4条回答
  •  醉话见心
    2021-01-19 04:52

    Try this:

    var fileText = File.ReadAllText(@"C:\Users\RichardsPC\Documents\TestText.txt");
    var words = fileText.Split(' ')
    var finalValue = fileText.OrderByDescending(n=> n.Length).First();
    Console.WriteLine("Longest word: " + finalValue");
    

提交回复
热议问题