29

I need to translate a string of characters, for example "Hello", into a string of numbers which is the ASCII numeric codes.

Example: 0 -> 48; a -> 97, etc.

Does anyone know an R function to do this? Hopefully, the function or piece of code will translate "Hello" into a numeric string like

c(72, 101, 108, 108, 111)
0

1 Answer 1

50

I guess you mean utf8ToInt, see the R manuals:

utf8ToInt("Hello")
# [1]  72 101 108 108 111

Or, if you want a mapping of the letters to their codes:

sapply(strsplit("Hello", NULL)[[1L]], utf8ToInt)
#  H   e   l   l   o 
# 72 101 108 108 111 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.