Skip to content

Commit

Permalink
bazelbuild#185, add removeprefix/removesuffix to the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmitchell authored and laurentlb committed Feb 15, 2022
1 parent 200a5a9 commit a2d07b2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -3926,6 +3930,32 @@ If S does not contain `x`, `partition` returns `(S, "", "")`.
"one/two/three".partition("/") # ("one", "/", "two/three")
```

<a id='string·removeprefix'></a>
### 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"
```

<a id='string·removesuffix'></a>
### 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"
```

<a id='string·replace'></a>
### string·replace

Expand Down

0 comments on commit a2d07b2

Please sign in to comment.