private string RegexStrategy(string Input) { MaskFormula maskFormula = _provider.MaskFormulas .Where(m => m.ProviderCode == _ProviderCode) .Single(); Match match = Regex.Match(Input, maskFormula.MaskExpression); string _masked; int startPos = 0; int matchLen = 0; if (match.Success) { startPos = match.Groups.Count > 0 ? match.Groups[1].Index : 0; matchLen = match.Groups.Count > 0 ? match.Groups[1].Length : 0; } _masked = Input.Substring(0, startPos); for (int pos = startPos; pos < Input.Length; pos++) { string chr = Input.Substring(pos, 1); match = Regex.Match(chr, maskFormula.ReplaceRegex); if (match.Success && pos < (matchLen + startPos)) { _masked += maskFormula.MaskChar; } else { _masked += chr; } } return(_masked); }
public Masker(string Input, string ProviderCode) : this() { _MaskFormula = new MaskFormula(ProviderCode) { MaskFormulaType = MaskFormulaTypes.REGEX }; Strategy = RegexStrategy; _ProviderCode = ProviderCode; _input = Input; }