Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.