https://kotlinlang.org logo
#announcements
Title
# announcements
k

kartikpatodi

06/23/2019, 4:42 PM
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

tseisel

06/23/2019, 5:32 PM
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

kartikpatodi

06/23/2019, 5:35 PM
How to implement this functionality
k

karelpeeters

06/23/2019, 7:42 PM
for loops?
😂 2
k

kartikpatodi

06/23/2019, 7:45 PM
@karelpeeters Was looking if there is some other way or the "Kotlin way"..
k

karelpeeters

06/23/2019, 7:46 PM
Well you're going to have to be a bit more specific, I don't get how the masks and unsafe bits work.
k

kartikpatodi

06/23/2019, 7:49 PM
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

Dico

06/23/2019, 7:50 PM
Seems like an easy task with a for loop
👍🏻 4
g

GauthierPLM

06/24/2019, 2:00 AM
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 🙂
210 Views