filesstrings (version 2.0.0)

trim_anything: Trim something other than whitespace

Description

The stringi and stringr packages let you trim whitespace, but what if you want to trim something else from either (or both) side(s) of a string? This function lets you select which pattern to trim and from which side(s).

Usage

trim_anything(string, pattern, side = "both")

Arguments

string

A string.

pattern

A string. The pattern to be trimmed (not interpreted as regular expression). So to trim a period, use char = "." and not char = "\\.").

side

Which side do you want to trim from? "both" is the default, but you can also have just either "left" or "right" (or optionally the shortened "b", "l" and "r").

Value

A string.

Examples

Run this code
# NOT RUN {
trim_anything("..abcd.", ".", "left")
trim_anything("-ghi--", "-")
trim_anything("-ghi--", "--")
# }

Run the code above in your browser using DataCamp Workspace