pattern
match.stri_trim_both(str, pattern = "^WHITE_SPACE")stri_trim_left(str, pattern = "^WHITE_SPACE")
stri_trim_right(str, pattern = "^WHITE_SPACE")
stri_trim(str, side = c("both", "left", "right"), pattern = "^WHITE_SPACE")
^WHITE_SPACE
`stri_trim
only]; defaults
to "both"
str
and pattern
.stri_trim
is a convenience function, which
dispatches control to stri_trim_*
. Unless you are
very lazy, do not use it: it is slower.
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 or a negation of
some character class, i.e. with ^
at the beginning).
With these functions you may very quickly 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 `WHITE_SPACE
` (more
general) and general character category `Z
`, see
stringi-search-charclass
stri_count_charclass
;
stri_detect_charclass
;
stri_extract_all_charclass
,
stri_extract_all_charclass
,
stri_extract_first_charclass
,
stri_extract_first_charclass
,
stri_extract_last_charclass
,
stri_extract_last_charclass
;
stri_locate_all_charclass
,
stri_locate_all_charclass
,
stri_locate_first_charclass
,
stri_locate_first_charclass
,
stri_locate_last_charclass
,
stri_locate_last_charclass
;
stri_replace_all_charclass
,
stri_replace_all_charclass
,
stri_replace_first_charclass
,
stri_replace_first_charclass
,
stri_replace_last_charclass
,
stri_replace_last_charclass
;
stri_split_charclass
,
stri_split_charclass
;
stringi-search-charclass
;
stringi-search
stri_trim_left("aaa")
stri_trim_right("rexamine.com/", "^P")
stri_trim_both("Total of 23.5 bitcoins. ", "N")
stri_trim_both("Total of 23.5 bitcoins. ", "L")
Run the code above in your browser using DataLab