StrTrim | R Documentation |
The function removes whitespace characters as spaces, tabs and newlines from the beginning and end of the supplied string.
Whitespace characters occurring in the middle of the string are retained.
Trimming with method "left"
deletes only leading whitespaces, "right"
only trailing.
Designed for users who were socialized by SQL.
StrTrim(x, pattern = " \t\n", method = "both")
x |
the string to be trimmed. |
pattern |
the pattern of the whitespaces to be deleted, defaults to space, tab and newline: |
method |
one out of |
The functions are defined depending on method as
both: gsub( pattern=gettextf("^[%s]+|[%s]+$", pattern, pattern), replacement="", x=x)
left: gsub( pattern=gettextf("^[%s]+",pattern), replacement="", x=x)
right: gsub( pattern=gettextf("[%s]+$",pattern), replacement="", x=x)
the string x without whitespaces
Andri Signorell <andri@signorell.net>
String functions:
trimws
, nchar
, match
, grep
, regexpr
, substr
, sub
, gsub
,
StrTrunc
, StrDist
StrTrim(" Hello world! ")
StrTrim(" Hello world! ", method="left")
StrTrim(" Hello world! ", method="right")
# user defined pattern
StrTrim(" ..Hello ... world! ", pattern=" \\.")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.