Skip to content

stripPrefix

Removes a prefix from a string if it exists.

stripPrefix

Signature

typescript
function stripPrefix(str: string, prefix: string): string

Parameters

  • str - The string to strip
  • prefix - The prefix to remove

Returns

String without the prefix.

Examples

typescript
import { stripPrefix } from 'strio'

stripPrefix('Hello world', 'Hello ')
// "world"

stripPrefix('test', 'foo')
// "test" (no change)

See Also

Released under the MIT License.