1. 程式人生 > >如何查詢一個字串中重複次數最多的字元,返回這個字元的個數和字元

如何查詢一個字串中重複次數最多的字元,返回這個字元的個數和字元

{
        
string str ="1232143546534135164161";
        
foreach(char c in str)
        
{
            Check(c);
        }

        
char maxChar = Char.MinValue;
        
int maxValue =0;
        
foreach(KeyValuePair<charint> kvp in sd)
        
{
            Console.WriteLine(
"Dictionary has a Key : {0} and Value: {1}
", kvp.Key, kvp.Value);
            
if(kvp.Value > maxValue)
            
{
                maxValue 
= kvp.Value;
                maxChar 
= kvp.Key;
            }

        }

        
        Console.WriteLine(
"Max char is {0}, times is {1}.", maxChar, maxValue);
        
        Console.ReadLine();
    }