CSharp examples for Language Basics:string
Count Character in a string
using System;/*from w ww . ja va2 s.c o m*/ class CharacterCounter { public static void Main() { string myText; int charCount = 0; char ch; int index = 0; Console.WriteLine("Enter some text"); myText = Console.ReadLine(); while (index < myText.Length) { ch = myText[index]; if (!char.IsWhiteSpace(ch)) charCount++; index++; } Console.WriteLine("Number of non-white-space characters: {0:N0}", charCount); } }