From a2d07b2b5bccf0157be57b572c2cfc053aeb9da8 Mon Sep 17 00:00:00 2001 From: Neil Mitchell Date: Fri, 28 May 2021 11:04:05 +0100 Subject: [PATCH] #185, add removeprefix/removesuffix to the spec --- spec.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec.md b/spec.md index 3fc0e30..b555c66 100644 --- a/spec.md +++ b/spec.md @@ -164,6 +164,8 @@ interact with the environment. * [string·lower](#string·lower) * [string·lstrip](#string·lstrip) * [string·partition](#string·partition) + * [string·removeprefix](#string·removeprefix) + * [string·removesuffix](#string·removesuffix) * [string·replace](#string·replace) * [string·rfind](#string·rfind) * [string·rindex](#string·rindex) @@ -777,6 +779,8 @@ Strings have several built-in methods: * [`lower`](#string·lower) * [`lstrip`](#string·lstrip) * [`partition`](#string·partition) +* [`removeprefix`](#string·removeprefix) +* [`removesuffix`](#string·removesuffix) * [`replace`](#string·replace) * [`rfind`](#string·rfind) * [`rindex`](#string·rindex) @@ -3926,6 +3930,32 @@ If S does not contain `x`, `partition` returns `(S, "", "")`. "one/two/three".partition("/") # ("one", "/", "two/three") ``` + +### string·removeprefix + +`S.removeprefix(x)` removes the prefix `x` from the string S and returns the rest of the string. +If the prefix string is not found then it returns the original string. + +`removeprefix` fails if `x` is not a string. + +```python +"banana".removeprefix("ban") # "ana" +"banana".removeprefix("ana") # "banana" +``` + + +### string·removesuffix + +`S.removesuffix(x)` removes the suffix `x` from the string S and returns the rest of the string. +If the suffix string is not found then it returns the original string. + +`removesuffix` fails if `x` is not a string. + +```python +"banana".removesuffix("ana") # "ban" +"banana".removesuffix("ban") # "banana" +``` + ### string·replace