Description Usage Arguments Value Note See Also Examples
Truncate a string to be no longer than a specific number of bytes
1 | truncate_bytes(x, max_len = Inf)
|
x |
Vector of strings to truncate |
max_len |
Max length (in bytes). Can be one number or have the same lenth as |
x, truncated to max_len
bytes each. The function won't chop
multi-byte characters in half, so the result might be shorter than max_len
Requires package stringi
. This implementation is really inefficient.
stringi::stri_sub()
and base::substr()
1 2 3 4 5 6 | truncate_bytes(c("ab", "cde"), c(1, 2))
latin1_str <- "fa\xE7ile"
Encoding(latin1_str) <- "latin1"
truncate_bytes(latin1_str, 3)
truncate_bytes("ὯaὯa", 2) # empty string
truncate_bytes("ὯaὯa", 6) # Ὧa only
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.