According to the assignment, I need to enter an application into the console, then find the number of words in the text, the longest word in the text, output its length and, most importantly, if the text exceeds 140 characters, cut everything that exceeds and return the residual text

If I have coped with the first tasks using Google + msdn, then with the return of the text of 140 characters - serious problems.

I can not understand what to invest in a variable to substring worked. Code below. I am a beginner in programming, I will ask you to explain to me easier, please

Console.Write("Введите строку: "); string input = Console.ReadLine(); string[] str = input.Split(new Char[] { ' ', ',', '.', ':', '!', '?', ';' }, StringSplitOptions.RemoveEmptyEntries); int maxlen = 0, index = 0; for (int i = 0; i < str.Length; i++) { if (str[i].Length > maxlen) { maxlen = str[i].Length; index = i; } } Console.WriteLine("Самое длинное слово: {0}", str[index]); Console.WriteLine("Длинна самого длинного слова {0}", str[index].Length); int CountWords = input.Split(new char[] { ' ', ',', '.', ':', '!', '?', ';' }, StringSplitOptions.RemoveEmptyEntries).Length; Console.WriteLine("Количество слов в тексте {0}", CountWords); var textCount = 140; if(str[index].Length > textCount) { var shortText = str[index].Substring(140, 200); Console.WriteLine(shortText) } Console.ReadKey(); Console.ReadLine(); 
  • five
    input = input.Substring(0, 140); ? - tym32167
  • And why are you doing Split again to count the number of words? You already have an array of words, take int wordsCount = str.Length; How to trim the substring suggested above - B. Vandyshev

0