Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何找出字符串中的重复字符?_C#_Asp.net - Fatal编程技术网

C# 如何找出字符串中的重复字符?

C# 如何找出字符串中的重复字符?,c#,asp.net,C#,Asp.net,我使用整数计数的字符串 int count=0; string s="wow" 我使用foreach循环计算指定字符串中的字符数 foreach(char ch in s) { count++ } 那么,如何计算字符串中重复出现的字符(如“w”)。这样做 string s="wow"; int repeats= s.Length - s.ToCharArray().Distinct().Count(); 你喜欢这样吗 string s="wow"; int repeats

我使用整数计数的字符串

int count=0;
string s="wow"
我使用foreach循环计算指定字符串中的字符数

foreach(char ch in s)
{

count++
}
那么,如何计算字符串中重复出现的字符(如“w”)。

这样做

  string s="wow";
  int repeats= s.Length - s.ToCharArray().Distinct().Count();
你喜欢这样吗

  string s="wow";
  int repeats= s.Length - s.ToCharArray().Distinct().Count();
试试这个)

试试这个)


@老实说,头衔和问题说明了不同的事情。标题说;如何找到重复字符,但问题是如何计算重复字符。但似乎这两个问题都没有包含在重复的问题中。重新打开。“我的错!”沙纳托斯老实说,头衔和问题说明了不同的事情。标题说;如何找到重复字符,但问题是如何计算重复字符。但似乎这两个问题都没有包含在重复的问题中。重新打开。我的错。