-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreditCardMask.cs
32 lines (25 loc) · 1013 Bytes
/
CreditCardMask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
public class CreditCardMask
{
// Usually when you buy something, you're asked whether your credit card number,
// phone number or answer to your most secret question is still correct. However,
// since someone could look over your shoulder, you don't want that shown on your screen.
// Instead, we mask it.
// Your task is to write a function maskify, which changes all but the last four characters into '#'.
// Examples
// "4556364607935616" --> "############5616"
// "64607935616" --> "#######5616"
// "1" --> "1"
// "" --> ""
// "What was the name of your first pet?"
// "Skippy" --> "##ippy"
private const int UnMaskCount = 4;
// return masked string
public static string Maskify(string cc)
{
StringBuilder sb = new StringBuilder(cc);
for (int i = 0; i < sb.Length - UnMaskCount; ++i)
sb[i] = '#';
return sb.ToString();
}
}