在 R 编程中将字符值转换为 ASCII 值 – charToRaw()函数
R 语言中的charToRaw()函数用于将给定字符转换为其对应的 ASCII 值或“原始”对象。
Syntax: charToRaw(x)
Parameters:
x: Given characters to be converted
示例 1:
Python3
# R program to illustrate
# charToRaw function
# Calling charToRaw() function over
# some alphabets
x <- charToRaw("a")
y <- charToRaw("A")
z <- charToRaw("ab")
# Getting the corresponding ASCII value
x
y
z
Python3
# R program to illustrate
# charToRaw function
# Initializing some strings
a <- "Geeks"
b <- "GFG is a CS Portal"
# Calling charToRaw() function
# over above strings
c <- charToRaw(a)
d <- charToRaw(b)
# Getting the ASCII values of the above
# specified strings
c
d
输出 :
[1] 61
[1] 41
[1] 61 62
示例 2:
Python3
# R program to illustrate
# charToRaw function
# Initializing some strings
a <- "Geeks"
b <- "GFG is a CS Portal"
# Calling charToRaw() function
# over above strings
c <- charToRaw(a)
d <- charToRaw(b)
# Getting the ASCII values of the above
# specified strings
c
d
输出:
[1] 47 65 65 6b 73
[1] 47 46 47 20 69 73 20 61 20 43 53 20 50 6f 72 74 61 6c