hello friends,
can anyone tell me how to write a c sharp program to count characters from a given string?
Count program
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
MahaRank #2,573 · 543 reputationPosted Nov 14, 2014, 4:41 PM EST
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;
}
}
}
Joginder BangerRank #360 · 7K reputationPosted Nov 14, 2014, 6:50 PM EST
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);
}
VulpesRank #55 · 29.2K reputationPosted Nov 15, 2014, 9:03 AM EST