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

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

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

php - Cloud9 cloud IDE and CakePHP -