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

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

python - argument 2 to map() must support iteration -

javafx - How to wait cancellation of task after Service#cancel? -