コード例 #1
0
 /// <summary>
 /// Mask the source string with the default mask char.
 /// </summary>
 /// <param name="sourceValue">Original string to mask.</param>
 /// <param name="style">The masking style to use (all characters or just alpha-nums).</param>
 /// <returns>The masked account number.</returns>
 public static string Mask(this string sourceValue, MaskStyle style)
 {
     return(Mask(sourceValue, DefaultMaskCharacter, 0, style));
 }
コード例 #2
0
 /// <summary>
 /// Mask the source string with the mask char.
 /// </summary>
 /// <param name="sourceValue">Original string to mask.</param>
 /// <param name="maskChar">The character to use to mask the source.</param>
 /// <param name="style">The masking style to use (all characters or just alpha-nums).</param>
 /// <returns>The masked account number.</returns>
 public static string Mask(this string sourceValue, char maskChar, MaskStyle style)
 {
     return(Mask(sourceValue, maskChar, 0, style));
 }
コード例 #3
0
 /// <summary>
 /// Mask the source string with the default mask char except for the last exposed digits.
 /// </summary>
 /// <param name="sourceValue">Original string to mask.</param>
 /// <param name="numExposed">Number of characters exposed in masked value.</param>
 /// <param name="style">The masking style to use (all characters or just alpha-nums).</param>
 /// <returns>The masked account number.</returns>
 public static string Mask(this string sourceValue, int numExposed, MaskStyle style)
 {
     return(Mask(sourceValue, DefaultMaskCharacter, numExposed, style));
 }
コード例 #4
0
        /// <summary>
        /// Mask the source string with the mask char except for the last exposed digits.
        /// </summary>
        /// <param name="sourceValue">Original string to mask.</param>
        /// <param name="maskChar">The character to use to mask the source.</param>
        /// <param name="numExposed">Number of characters exposed in masked value.</param>
        /// <param name="style">The masking style to use (all characters or just alpha-nums).</param>
        /// <returns>The masked account number.</returns>
        public static string Mask(this string sourceValue, char maskChar, int numExposed, MaskStyle style)
        {
            var maskedString = sourceValue;

            if (sourceValue.IsLengthAtLeast(numExposed))
            {
                var builder = new StringBuilder(sourceValue.Length);
                int index   = maskedString.Length - numExposed;

                if (style == MaskStyle.AlphaNumericOnly)
                {
                    CreateAlphaNumMask(builder, sourceValue, maskChar, index);
                }
                else
                {
                    builder.Append(maskChar, index);
                }

                builder.Append(sourceValue.Substring(index));
                maskedString = builder.ToString();
            }

            return(maskedString);
        }