c# - Counting number of occurrences of characters from array in string? -
i'm writing code determine whether password contains enough punctuation characters.
how count number of occurrences of characters set?
something along these lines:
private const string nonalphanumericcharset = "#*!?£$+-^<>[]~()&"; ... public static bool passwordmeetsstrengthrequirements(string password) { return password.length >= minimum_password_length && password.numberofoccurences(nonalphanumericcharset.tochararray()) >= minimum_nonalphanumeric_chars; } bonus points elegant linq solution.
how count number of occurences of characters set?
var count = password.count(nonalphanumericcharset.contains);
Comments
Post a Comment