EVOLUTION-MANAGER
Edit File: utf8_nchar.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Count the number of characters in a character vector</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for utf8_nchar {cli}"><tr><td>utf8_nchar {cli}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Count the number of characters in a character vector</h2> <h3>Description</h3> <p>By default it counts Unicode grapheme clusters, instead of code points. </p> <h3>Usage</h3> <pre> utf8_nchar(x, type = c("chars", "bytes", "width", "graphemes", "codepoints")) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>Character vector, it is converted to UTF-8.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>Whether to count graphemes (characters), code points, bytes, or calculate the display width of the string.</p> </td></tr> </table> <h3>Value</h3> <p>Numeric vector, the length of the strings in the character vector. </p> <h3>See Also</h3> <p>Other UTF-8 string manipulation: <code><a href="utf8_graphemes.html">utf8_graphemes</a>()</code>, <code><a href="utf8_substr.html">utf8_substr</a>()</code> </p> <h3>Examples</h3> <pre> # Grapheme example, emoji with combining characters. This is a single # grapheme, consisting of five Unicode code points: # * `\U0001f477` is the construction worker emoji # * `\U0001f3fb` is emoji modifier that changes the skin color # * `\u200d` is the zero width joiner # * `\u2640` is the female sign # * `\ufe0f` is variation selector 16, requesting an emoji style glyph emo <- "\U0001f477\U0001f3fb\u200d\u2640\ufe0f" cat(emo) utf8_nchar(emo, "chars") # = graphemes utf8_nchar(emo, "bytes") utf8_nchar(emo, "width") utf8_nchar(emo, "codepoints") # For comparision, the output for width depends on the R version used: nchar(emo, "chars") nchar(emo, "bytes") nchar(emo, "width") </pre> <hr /><div style="text-align: center;">[Package <em>cli</em> version 3.4.1 <a href="00Index.html">Index</a>]</div> </body></html>