
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);
- }

Michal HabalcikPosted Dec 2, 2014, 8:21 AM
I think that the code should be much simpler. U can use Linq to count the chars within a string thus make the code more readable. something like string a = "Mama"; int t = a.Count(c => c.Equals('a')); also, that MVC snippet will be useless for unexperienced developers as they won't be able to compile it.