L
L
Lordao2021-06-24 14:13:45
Kotlin
Lordao, 2021-06-24 14:13:45

How to replace multiple elements from a string in Kotlin?

There is a string "2342423534353" .

You need to replace all elements, for example, from 3 to 7 positions with another character, for example, # . To end up with "23#####534353" .

The replaceRange method removes all elements in the current range and replaces with one character, and it turns out to be "23#534353"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Novoselov, 2021-06-24
@zkod

println("2342423534353".replaceRange(3,7,"#####"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question