/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System/String/Overview/csharp/index11.cs
24 строки
755 B
Genevieve Warren
Add remarks for core types (#38970)
05 янв 2024, 22:14
Не верифицирован
05 янв 2024, 22:14
71d1377
Код
Авторство
О чём код?
using System; public class Example7 { public static void Main() { // <Snippet4> string s1 = "This string consists of a single short sentence."; int nWords = 0; s1 = s1.Trim(); for (int ctr = 0; ctr < s1.Length; ctr++) { if (Char.IsPunctuation(s1[ctr]) | Char.IsWhiteSpace(s1[ctr])) nWords++; } Console.WriteLine("The sentence\n {0}\nhas {1} words.", s1, nWords); // The example displays the following output: // The sentence // This string consists of a single short sentence. // has 8 words. // </Snippet4> } }