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 -

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -