Count the individual characters in a string

Posted by Mani654mani under C# on 5/31/2012 | Points: 10 | Views : 2236 | Status : [Member] | Replies : 3
Hi,


I have a string as given below:

string str = "sssmmffgggggg"

but i need to display the output as given below by using c#.


Ouput is:

s = 3
m = 2
f = 2
g = 6

Thanks in advance.




Responses

Posted by: Sabarimahesh on: 5/31/2012 [Member] Bronze | Points: 25

Up
0
Down
http://www.dotnetfunda.com/codes/code2605-count-the-particular-word.aspx

Search it you may geet some idea

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Mani654mani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 5/31/2012 [Member] Bronze | Points: 25

Up
0
Down
http://www.dotnetfunda.com/codes/code2604-code-for-count-the-string.aspx

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Mani654mani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 5/31/2012 [Member] Bronze | Points: 25

Up
0
Down
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
public static class Program
{

static void Main(string[] args)
{
string aa = "sabarimahesh";
char aaa = 'a';
Console.WriteLine(Individualchar(aa, aaa));
Console.ReadLine();
}

public static int Individualchar(string srtingsr, char Charfind)
{
int cnt = 0;
char[] ch = srtingsr.ToCharArray();
foreach (char c in ch)
{
if (c == Charfind)
{
cnt++;
}
}
return cnt;
}


}
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Mani654mani, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response