"count max occuring character" Code Answer's

You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "count max occuring character" answered properly. Developers are finding an appropriate answer about count max occuring character related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like count max occuring character. Enter your desired code related query in the search bar and get every piece of information about C# code related question on count max occuring character. 

c# + max char frequency in string

By Wide-eyed WolfWide-eyed Wolf on Aug 03, 2020
//return the character that appears the maximum number of times in the string
//contain only ASCII characters, from the ranges ('a'-'z','A'-'Z','0'-'9'), and case sensitive
//If there is a tie in the maximum number of times a character appears in the string, return the character that appears first in the string 

public static void Main(string[] args)
{
  CharCounter("This is a neat day for Things about Coding9999");        
}
public static void CharCounter(string str) 
{
    string strValidated = "";
    str = str.Replace(" ", "");     //Remove all spaces

  //Validate alpha-numberic only
    if (Regex.IsMatch(str, @"^[A-Za-z0-9]+$")) strValidated = str;
    else throw new FormatException("--------> Only Apha Numeric values allowed");

    Dictionary<char, int> dict = new Dictionary<char, int>();

    foreach (char c in strValidated)    //Create Dictionary
    {
      if (dict.ContainsKey(c)) dict[c] = dict[c] + 1;
      else dict.Add(c, 1);
    }
  //Sort(K,V) by Highest Values
    var ordered = dict.OrderByDescending(x => x.Value)
      .ToDictionary(d => d.Key, d => d.Value);

  //var singleEntryDict = ordered.First();  
    var result = ordered.Take(1)
      .ToDictionary(d => d.Key, d => d.Value);

    foreach (var item in result.Keys)
    {
      Console.WriteLine($"Key= {item} : Value= {result[item]}");
    }
            
}

Add Comment

1

All those coders who are working on the C# based application and are stuck on count max occuring character can get a collection of related answers to their query. Programmers need to enter their query on count max occuring character related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about count max occuring character for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of count max occuring character while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "count max occuring character". Visit this developer's friendly online web community, CodeProZone, and get your queries like count max occuring character resolved professionally and stay updated to the latest C# updates. 

C# answers related to "count max occuring character"

View All C# queries

C# queries related to "count max occuring character"

Browse Other Code Languages

CodeProZone