我正在编写代码来确定密码是否包含足够的标点字符。
如何计算集合中任何字符的出现次数?
沿着这些线的东西:
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/