.removePrefix()
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Oct 27, 2023Updated Nov 1, 2023
Contribute to Docs
The .removePrefix()
method in Kotlin is used to remove a specified prefix from a string if it is present. It returns a new string with the specified prefix removed if it exists. If the original string does not start with the specified prefix, the method returns the original string unchanged.
Syntax
String.removePrefix(prefix)
String
: The original string from which the prefix will be removed.prefix
: The prefix which will be removed from the original string.
Example
This example shows how to use the .removePrefix()
method to remove a prefix from a Kotlin string:
fun main() {val originalString = "HelloWorld.jpg"val prefix = "Hello"val modifiedString = originalString.removePrefix(prefix)println("Modified String: $modifiedString")}
The result will be printed as:
Modified String: World.jpg
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- itutu_981 total contribution
- Anonymous contributor
- itutu_98
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.