Overview:
In this article i would like to publish an article "Program to find Total Number of Characters in a given string eliminating white spaces".
Description:
Generally whenever we store data into a string then it includes white spaces also.So we need to eliminate white spaces characters and give total length of the string.
This process can be achievable by using for loop.So that get the white spaces count and eliminate it.
Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace pr
{
class Class2
{
static void
Main(string[] args)
{
string s = "Naga
Veerendra Parvataneni";
string s1 = string.Empty;
int i1 = 0;
for (int
i = 0; i < s.Length; i++)
{
if
(s[i] ==' ')
{
i1++;
}
}
Console.WriteLine("Total Length of a Given String:"+s.Length);
Console.WriteLine("Total Number of Blank Spaces:" + i1);
Console.WriteLine("Total Number of Characters in a Given String:"
+(s.Length-i1));
Console.ReadLine();
}
}
}Output:
No comments:
Post a Comment