Skip to content

String TrimPrefix

The string::trimprefix function removes a specified prefix from a string, if it exists.

Syntax

string::trimprefix(<string>, <prefix>)

Parameters

  • string: The input string.
  • prefix: The prefix to remove.

Returns

  • String: A new string without the specified prefix. If the prefix is not found, the original string is returned.

Example

Try it out below!
string::trimprefix("hello world", "hello ")

This function is useful for removing known prefixes from strings without manually checking for their presence.