Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp1
- {
- class Program
- {
- class getStringInfo
- {
- public static void doTheThings(string str)
- {
- int notWhiteSpaceSymbols = 0, wordCount = 0;
- double symbolToWordRatio;
- string lastCharsWord = string.Empty;
- for (int i = 1; i < str.Length; i++) //проверка последнего символа потом еще или как подумай
- {
- if (char.IsLetterOrDigit(str[i - 1]) == true)
- {
- notWhiteSpaceSymbols++;
- if (char.IsLetterOrDigit(str[i]) == false)
- {
- wordCount++;
- lastCharsWord += Convert.ToString(str[i - 1]);
- }
- }
- else if (char.IsWhiteSpace(str[i - 1]) == false)
- notWhiteSpaceSymbols++;
- }
- symbolToWordRatio = notWhiteSpaceSymbols / wordCount;
- Console.WriteLine("Количество слов: {0};", wordCount);
- Console.WriteLine("Количество символов без пробелов: {0};", notWhiteSpaceSymbols);
- Console.WriteLine("Соотношение количество символов без пробелов к количеству слов: {0};", symbolToWordRatio);
- Console.WriteLine("Слово из последних символов слов: \"{0}\";", lastCharsWord);
- }
- }
- static void Main(string[] args)
- {
- const string teststr = "Lorem Ipsum - это текст-\"рыба\", часто используемый в печати и вэб-дизайне.";
- string str = Console.ReadLine();
- getStringInfo.doTheThings(teststr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement