Is there a funtion in stdlib for masking a string?...
# announcements
k
Is there a funtion in stdlib for masking a string? I have a use case where a mask is provided say ##-## and a string say "1234" and unsafe bits say 2. So the result should be ##-34
t
Nope, that doesn't exist in the stdlib. The stdlib contains only general-purpose utilities, so that including it in all Kotlin projects doesn't increase the program size.
k
How to implement this functionality
k
for loops?
😂 2
k
@karelpeeters Was looking if there is some other way or the "Kotlin way"..
k
Well you're going to have to be a bit more specific, I don't get how the masks and unsafe bits work.
k
The unsafe bits are the number of digits from the last that can be exposed and and others are hidden and formatted as the mask
Like credit card numbers on the bank sms
d
Seems like an easy task with a for loop
👍🏻 4
g
Copy code
val str = "1234123412341234"
val masked = str.substring(str.length - 4).padStart(16, '#')
You can mask it like this. After you can find your own way to add “-” between every X characters 🙂
254 Views