R utf8ToInt
Get the first Unicode code point of a nonempty label.
A simple example
utf8ToInt
- Start with "A"
- Do this Read the first code point
- Result 65
Syntax
utf8ToInt(value)[1]
Run these examples in R
Save one example at a time as Lesson.R. Use R 4.x.
Rscript --vanilla Lesson.RInspect an emoji feedback tag
A feedback or ticket label includes an emoji that needs a full Unicode code point. Inspect the symbol at the right boundary so the value sent to the next component represents the entire character.
value <- "\U0001f600OK"
cat(utf8ToInt(value)[1], "\n", sep = "")
128512
U+1F600 has decimal value 128512.
Inspect a name initial
A compact printed code assigns meaning to particular positions. Locate the correct character for the requested field and check the indexing convention before sending the value to the display.
value <- "\u00c9mile"
cat(utf8ToInt(value)[1], "\n", sep = "")
201
The precomposed capital É has decimal value 201.
Read a parcel sorting code
The depot scans a parcel marked NC-17. The scanner stores the Unicode code point of the first letter. Which decimal value should appear in the log?
What to watch for
An encoded byte is not necessarily a code point. These inputs contain valid Unicode and begin at a character boundary.