PC Review


Reply
Thread Tools Rate Thread

charcter count in a string

 
 
Kuups
Guest
Posts: n/a
 
      3rd Feb 2005
Hi!

I have a question regarding the count if character within a string
like for example I have a string of

e.g.

123#123#

I would like to determine what is the code? of getting the # sign
which the answer is 2.


Hope you can help me on this.


Thanks and Regards..



 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd Feb 2005
Kuups <(E-Mail Removed)> wrote:
> I have a question regarding the count if character within a string
> like for example I have a string of
>
> e.g.
>
> 123#123#
>
> I would like to determine what is the code? of getting the # sign
> which the answer is 2.


public static int CountCharacters (string data, char c)
{
int count=0;
foreach (char x in data)
{
if (x==c)
{
count++;
}
}
return count;
}

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
=?Utf-8?B?UmFrZXNoIFJhamFu?=
Guest
Posts: n/a
 
      3rd Feb 2005
Hi Kuups,

string pattern = "12#3123#141#";
Console.WriteLine(pattern.Split('#').Length-1);

HTH,
Rakesh Rajan

"Kuups" wrote:

> Hi!
>
> I have a question regarding the count if character within a string
> like for example I have a string of
>
> e.g.
>
> 123#123#
>
> I would like to determine what is the code? of getting the # sign
> which the answer is 2.
>
>
> Hope you can help me on this.
>
>
> Thanks and Regards..
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula to count charcter in a range Dylan @ UAFC Microsoft Excel Worksheet Functions 9 15th Jan 2009 04:52 AM
Re: formula to count charcter in a range Glenn Microsoft Excel Worksheet Functions 0 14th Jan 2009 07:36 PM
Re: formula to count charcter in a range Don Guillett Microsoft Excel Worksheet Functions 0 14th Jan 2009 07:27 PM
Count instaces of charcter in field Barkster Microsoft Access Queries 9 25th Oct 2006 12:33 PM
find a charcter in string =?Utf-8?B?R2FiaQ==?= Microsoft VC .NET 1 4th Apr 2006 11:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:56 PM.