diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-05-31 22:20:36 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-05-31 22:20:36 +0200 |
commit | 2245ae18e3480057f98fc0e5d9f18091f32a5de0 (patch) | |
tree | 25c0729764687fadbdce05f0ed0694d91cd46abc /runtime | |
parent | fccd93f0917234b962ce07d1df3adf9d7105936f (diff) | |
download | vim-git-2245ae18e3480057f98fc0e5d9f18091f32a5de0.tar.gz |
patch 8.2.0868: trim() always trims both endsv8.2.0868
Problem: trim() always trims both ends.
Solution: Add an argument to only trim the beginning or end. (Yegappan
Lakshmanan, closes #6126)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index fb5ef738c..b753aae62 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2898,7 +2898,8 @@ tolower({expr}) String the String {expr} switched to lowercase toupper({expr}) String the String {expr} switched to uppercase tr({src}, {fromstr}, {tostr}) String translate chars of {src} in {fromstr} to chars in {tostr} -trim({text} [, {mask}]) String trim characters in {mask} from {text} +trim({text} [, {mask} [, {dir}]]) + String trim characters in {mask} from {text} trunc({expr}) Float truncate Float {expr} type({name}) Number type of variable {name} undofile({name}) String undo file name for {name} @@ -10245,13 +10246,22 @@ tr({src}, {fromstr}, {tostr}) *tr()* Can also be used as a |method|: > GetText()->tr(from, to) -trim({text} [, {mask}]) *trim()* +trim({text} [, {mask} [, {dir}]]) *trim()* Return {text} as a String where any character in {mask} is - removed from the beginning and end of {text}. + removed from the beginning and/or end of {text}. + If {mask} is not given, {mask} is all characters up to 0x20, which includes Tab, space, NL and CR, plus the non-breaking space character 0xa0. - This code deals with multibyte characters properly. + + The optional {dir} argument specifies where to remove the + characters: + 0 remove from the beginning and end of {text} + 1 remove only at the beginning of {text} + 2 remove only at the end of {text} + When omitted both ends are trimmed. + + This function deals with multibyte characters properly. Examples: > echo trim(" some text ") @@ -10259,7 +10269,9 @@ trim({text} [, {mask}]) *trim()* echo trim(" \r\t\t\r RESERVE \t\n\x0B\xA0") . "_TAIL" < returns "RESERVE_TAIL" > echo trim("rm<Xrm<>X>rrm", "rm<>") -< returns "Xrm<>X" (characters in the middle are not removed) +< returns "Xrm<>X" (characters in the middle are not removed) > + echo trim(" vim ", " ", 2) +< returns " vim" Can also be used as a |method|: > GetText()->trim() |