如何将字符转换为ASCii代码或相应的二进制字符串。 “R” [英] How to convert characters into ASCii code or corresponding Binary string. "R"
本文介绍了如何将字符转换为ASCii代码或相应的二进制字符串。 “R”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将一个字符串,例如Hello
翻译成一个数字字符串,这是ASCII数字代码。
I need to translate a string of characters, for example "Hello"
, into a string of numbers which is the ASCII numeric codes.
示例: 0 - > 48; a - > 97
等。
有没有人知道R函数这样做?希望,函数或代码片段将Hello
翻译成如
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)
推荐答案
我想你的意思是 utf8ToInt
,请参阅R docs http://www.inside-r.org/r-doc/base/utf8ToInt
I guess you mean utf8ToInt
, see the R docs http://www.inside-r.org/r-doc/base/utf8ToInt
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
这篇关于如何将字符转换为ASCii代码或相应的二进制字符串。 “R”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文