Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Count a Char Number of Times in a String
WhatsApp
Ashok Paladugula
10y
4.3
k
0
0
25
Blog
C# Code
public
ActionResult GetRepeatedCharactorCount(
string
enterdString)
{
string
inputString = enterdString;
List<
string
> resultStringList =
new
List<
string
>();
char
[] chrs = inputString.ToCharArray();
for
(
int
i = 0; i < chrsList.Length; i++)
{
int
j = 0, count = 0;
while
((j = inputString.IndexOf(chrsList[i], j)) != -1)
{
count++;
j++;
}
var outputting =
string
.Format(
"{0} Number of times repeat : {1} in {2}"
, chrsList[i], count, inputString);
if
(resultStringList.IndexOf(outputString) == -1)
{
resultStringList.Add(outputString);
}
}
return
Json(
new
{ result = resultStringList}, JsonRequestBehavior.AllowGet);
}
Count a Char Number of Times in a String
Up Next
How to Count Occurrences of a String Within Another String in C#
Ebook Download
View all
Printing in C# Made Easy
Read by 22.4k people
Download Now!
Learn
View all
Membership not found