This is the color-aware counterpart of base::substring()
.
It works exactly like the original, but keeps the colors in the
substrings. The ANSI escape sequences are ignored when
calculating the positions within the string.
ansi_substring(text, first, last = 1000000L)
text | Character vector, potentially ANSI styled, or a vector to
coarced to character. It is recycled to the longest of |
---|---|
first | Starting index or indices, recycled to match the length
of |
last | Ending index or indices, recycled to match the length
of |
Character vector of the same length as x
, containing
the requested substrings. ANSI styles are retained.
Other ANSI string operations:
ansi_align()
,
ansi_nchar()
,
ansi_strsplit()
,
ansi_substr()
#> red default green#> red d#> red default gre#> d def#> [1] "red d"#> [1] "red default gre"#> [1] "d def"#> another multi-style text#> other #> her multi-styl#> [1] "other" "her multi-styl"