如何将字符转换为ASCII码? [英] How to convert characters into ASCII code?
本文介绍了如何将字符转换为ASCII码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将字符串(例如"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)
推荐答案
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
这篇关于如何将字符转换为ASCII码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文