How to convert characters into ASCII code?

前端 未结 1 669
轻奢々
轻奢々 2020-12-20 11:12

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

1条回答
  •  悲&欢浪女
    2020-12-20 12:00

    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 
    

    0 讨论(0)
提交回复
热议问题