c# - 计算字符串中数组中字符的出现次数?

标签 c# algorithm

我正在编写代码来确定密码是否包含足够的标点字符。

如何计算集合中任何字符的出现次数?

沿着这些线的东西:

private const string nonAlphaNumericCharSet = "#*!?£$+-^<>[]~()&";
...
public static bool PasswordMeetsStrengthRequirements(string password)
{
    return password.Length >= MINIMUM_PASSWORD_LENGTH && password.NumberOfOccurences(nonAlphaNumericCharSet.ToCharArray()) >= MINIMUM_NONALPHANUMERIC_CHARS;
}

优雅的 linq 解决方案的奖励积分。

最佳答案

How do I count the number of occurences of any characters from a set?

var count = password.Count(nonAlphaNumericCharSet.Contains);

关于c# - 计算字符串中数组中字符的出现次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16688647/

相关文章:

c# - WP7 应用程序中的 "Navigation is not allowed when the task is not in the foreground"

algorithm - 存在大量重复项时二分查找算法的性能

c# - 硬币变化,只是不能正确

algorithm - Netlogo,创建避障算法

c# - 根据切换数组检查哪个切换已更改

c# - MD5 散列的奇怪行为

c# - 异常(exception)是关于在 next() 之后不修改响应的规则的异常(exception)吗?

string - 如何有效地从字符串中删除重复字符?

algorithm - TB 数据中出现频率最高的单词

c# - 将范围添加到集合