col_nchar: Count number of characters in an ANSI colored string

Description Usage Arguments Value See Also Examples

View source: R/string_operations.r

Description

This is a color-aware counterpart of base::nchar(), which does not do well, since it also counts the ANSI control characters.

Usage

1

Arguments

x

Character vector, potentially ANSO styled, or a vector to be coarced to character.

...

Additional arguments, passed on to base::nchar() after removing ANSI escape sequences.

Value

Numeric vector, the length of the strings in the character vector.

See Also

Other ANSI string operations: col_align, col_strsplit, col_substring, col_substr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
str <- paste(
  red("red"),
  "default",
  green("green")
)

cat(str, "\n")
nchar(str)
col_nchar(str)
nchar(strip_style(str))

crayon documentation built on May 2, 2019, 8:16 a.m.