pattern
match.stri_trim_both(str, pattern = "\\P{Wspace}")stri_trim_left(str, pattern = "\\P{Wspace}")
stri_trim_right(str, pattern = "\\P{Wspace}")
stri_trim(str, side = c("both", "left", "right"), pattern = "\\P{Wspace}")
\P{Wspace}
.stri_trim
only]; defaults to "both"
str
and pattern
.stri_trim
is a wrapper, which calls stri_trim_left
or stri_trim_right
as appropriate. It's slightly slower than trim_left or
trim_right, and so shouldn't be used except for convenience.
Contrary to many other string processing libraries,
our trimming functions are quite general. A character class,
given by pattern
,
may be adjusted to suit your needs (most often you will use the default
value). On the other hand, for replacing pattern matches with
arbitrary replacement string, see stri_replace
.
Interestingly, with these functions you may sometimes extract data, which
in some cases require using regular expressions. E.g. you may get
"23.5"
out of "total of 23.5 bitcoins"
.
For trimming whitespaces, please note the difference
between Unicode binary property `\p{Wspace}
` (more general)
and general character category `\p{Z}
`,
see stringi-search-charclass.
stringi-search-charclass
;
stringi-search
Other search_replace: stri_replace_na
;
stri_replace
,
stri_replace_all
,
stri_replace_all_charclass
,
stri_replace_all_coll
,
stri_replace_all_fixed
,
stri_replace_all_regex
,
stri_replace_first
,
stri_replace_first_charclass
,
stri_replace_first_coll
,
stri_replace_first_fixed
,
stri_replace_first_regex
,
stri_replace_last
,
stri_replace_last_charclass
,
stri_replace_last_coll
,
stri_replace_last_fixed
,
stri_replace_last_regex
;
stringi-search
stri_trim_left("aaa")
stri_trim_right("rexamine.com/", "\\p{P}")
stri_trim_both("Total of 23.5 bitcoins. ", "\\p{N}")
stri_trim_both("Total of 23.5 bitcoins. ", "\\p{L}")
Run the code above in your browser using DataLab