Data Science Desktop Survival Guide
by Graham Williams |
|||||
Trim and Pad |
ws <- c(" abc", "def ", " ghi ")
str_trim(ws)
str_trim(ws, side="left")
str_trim(ws, side="right")
str_trim(ws, side="both")
Conversely we can also pad a string with additional characters for up to a specified width using stringr::str_pad(). The default padding character is a space but we can override that. |
str_pad("abc", width=7)
str_pad("abc", width=7, side="left")
str_pad("abc", width=7, side="right")
str_pad("abc", width=7, side="both", pad="#")
|