From 295ac5ab5e840af6051bed5ec9d9acc3c73445de Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Thu, 22 Mar 2018 23:04:02 +0100 Subject: patch 8.0.1630: trimming white space is not that easy Problem: Trimming white space is not that easy. Solution: Add the trim() function. (Bukn, closes #1280) --- runtime/doc/eval.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 663f491df..387186f83 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2463,6 +2463,7 @@ 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} trunc({expr}) Float truncate Float {expr} type({name}) Number type of variable {name} undofile({name}) String undo file name for {name} @@ -8659,6 +8660,22 @@ tr({src}, {fromstr}, {tostr}) *tr()* echo tr("", "<>", "{}") < returns "{blob}" +trim({text}[, {mask}]) *trim()* + Return {text} as a String where any character in {mask} is + removed from the beginning and 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. + + Examples: > + echo trim(" \r\t\t\r RESERVE \t \t\n\x0B\x0B")."_TAIL" +< returns "RESERVE_TAIL" > + echo trim("needrmvRESERVEnnneeedddrrmmmmvv", "ednmrv") +< returns "RESERVE" > + echo trim("rmrrmm", "rm") +< returns "any_chas" + trunc({expr}) *trunc()* Return the largest integral value with magnitude less than or equal to {expr} as a |Float| (truncate towards zero). -- cgit v1.2.1