hello friends,
can anyone tell me how to write a c sharp program to count characters from a given string?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Nov 15, 2014, 2:03 PM
Joginder BangerPosted Nov 14, 2014, 11:50 PM
static void Main(string[] args)
{
string hold = string.Empty;
string str = "tes ing";
string [] temp = str.Split(' '); ;
for (int i = 0; i < temp.Length; i++)
{
hold += temp[i];
}
Console.WriteLine( hold.Length);
}
MahaPosted Nov 14, 2014, 9:41 PM
using System;
namespace count_characters
{
class Program
{
static void Main(string[] args)
{
int result = CountNonSpaceChars("Seenu Chiranjeevi");
Console.WriteLine(result);
Console.ReadKey();
}
static int CountNonSpaceChars(string value)
{
int result = 0;
foreach (char c in value)
{
if (!char.IsWhiteSpace(c))
{
result++;
}
}
return result;
}
}
}