strip_invalid_chars: Removes invalid characters from a string.

Description Usage Arguments Value Examples

View source: R/internal-string.R

Description

Removes invalid characters from a string, leaving only digits.

Usage

1
2
3
4
5
strip_invalid_chars(x, invalid_chars, char_desc = gettext("invalid"))

strip_non_alphanumeric(x)

strip_non_numeric(x, allow_x = FALSE, allow_plus = FALSE)

Arguments

x

Input to strip.

invalid_chars

A regular expression detailing characters to remove.

char_desc

A string describing the characters to remove.

allow_x

If TRUE, the letter "X" is allowed - useful for check digits.

allow_plus

If TRUE, the symbol "+" is allowed - useful for phone numbers.

Value

A character vector of the same length as x, consisting of strings without the characters detailed in the invalid_chars.

Examples

1
2
3
4
5
6
7
8
9
## Not run: 
strip_invalid_chars(
  "  We're floating\tin    space\n\n\n", "[[:space:]]", "whitespace"
)
strip_non_numeric(" +44 800-123-456 ", allow_plus = TRUE)
#Inputs such as factors as coerced to character.
strip_non_alphanumeric(factor(c(" A1\t1AA.", "*(B2^2BB)%")))

## End(Not run)

assertive.strings documentation built on May 1, 2019, 8:45 p.m.