Re: Count all occurrences of a character in a string
From: Paul E Collins (find_my_real_address_at_CL4.org)
Date: 12/06/04
- Next message: Bajgon: "Re: How to select known DataRow from underlying DataTable on DataGrid"
- Previous message: Tomas Vera: "Re: metadata operation failed (8013110E) : Database file is corrupt and may not be usable."
- In reply to: thomaz: "Count all occurrences of a character in a string"
- Next in thread: C# Learner: "Re: Count all occurrences of a character in a string"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 6 Dec 2004 16:35:26 +0000 (UTC)
"thomaz" <suppa@nce.ufrj.br> wrote:
> There is a string method to count the total number
> of a specified character in a string.
private static int CountChar(char c, string s)
{
int pos = 0, count = 0;
while ((pos = s.IndexOf(c, pos)) != -1)
{
count++;
pos++;
}
return count;
}
P.
- Next message: Bajgon: "Re: How to select known DataRow from underlying DataTable on DataGrid"
- Previous message: Tomas Vera: "Re: metadata operation failed (8013110E) : Database file is corrupt and may not be usable."
- In reply to: thomaz: "Count all occurrences of a character in a string"
- Next in thread: C# Learner: "Re: Count all occurrences of a character in a string"
- Messages sorted by: [ date ] [ thread ]