Scala: How to mask the first N characters of a string -
given string represents credit card number...
val creditcardno = "1111222233334444"
... how mask first 12 characters *
?
val maskedcreditcardno = "************4444"
replace digit symbols unless 4 characters remain:
creditcardno.replaceall("\\d(?=\\d{4})", "*")
Comments
Post a Comment