To change the phone number format from "+79998887766" to "+79*66" in Kotlin for Android, you can use the following code:
val phoneNumber = "+79998887766"
val formattedNumber = phoneNumber.replaceRange(2, phoneNumber.length - 2, "*".repeat(phoneNumber.length - 6))
val newNumber = "+$formattedNumber"
Here, replaceRange()
method is used to replace the characters between index positions 2 and the length of the string minus 2 with asterisks. The repeat()
method is used to generate a string of asterisks with the same length as the replaced substring. Finally, the +
symbol is added at the beginning to complete the new phone number format.
To modify the string color, you can use the following code:
textView.setTextColor(ContextCompat.getColor(context, R.color.my_color))
Here, textView
is the text view where you want to modify the color, context
is the context of the activity or fragment, and R.color.my_color
is the resource ID of the color you want to use. You can create a new color resource in the colors.xml
file in the res/values
directory of your project.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-05 01:37:45 +0000
Seen: 13 times
Last updated: Jul 05 '23