.removeRange()
Anonymous contributor
Anonymous contributor2 total contributions
Anonymous contributor
Published Oct 28, 2023
Contribute to Docs
The removeRange()
method in Kotlin is used to remove a specified range of characters from a string. It returns a new string with the specified range of characters removed.
Syntax
val modifiedString = originalString.removeRange(startIndex, endIndex)
originalString
: The original string from which you want to remove characters.
startIndex
: The index of the first character to be removed (inclusive).
endIndex
: The index of the character following the last character to be removed (exclusive).
Example
This example shows how to use the removeRange()
method to remove a range of characters from a Kotlin string:
fun main() {val originalString = "Hello, World!"val startIndex = 5val endIndex = 12val modifiedString = originalString.removeRange(startIndex, endIndex)println("Modified String: $modifiedString")}
In this example, removeRange()
method is used to remove characters between indices 5 (inclusive) and 12 (exclusive). The result will be printed as:
Modified String: Hello!
All contributors
- Anonymous contributorAnonymous contributor2 total contributions
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.