Tuesday, April 16, 2013

Replace Characters in a String with special symbols



string s = ReplaceAt(txtCreditCardNumber.Text, 12, 4, '*');


public string ReplaceAt(string input, int index, int count, char newChar)
    {
        if (input == null)
        {
            throw new ArgumentNullException("input");
        }
        char[] chars = input.ToCharArray();
        for (int i = 0; i < count; i++)
        {
            chars[index] = newChar;
            index++;
        }
        return new string(chars);
    }