如何在gnuplot中找出字符的ASCII码

时间:2019-03-23 10:51:25

标签: gnuplot

有人知道如何在gnuplot中找出字符的ASCII码吗?

没有官方功能可以做到这一点,所以它一定是某种技巧。

(好的,我找到了一种方法,直接在下面回答)

1 个答案:

答案 0 :(得分:3)

代替ord(ch)函数,可以构建一个包含所有字符的字符串,并使用strstrt()函数查找相关字符的位置。

# make a string that contains all ASCII chars from 1 to 255
ALLCHARS = ''; do for [i=1:255] {ALLCHARS = ALLCHARS.sprintf('%c',i)}
# return position of character in ALLCHARS if ch contains 1 char, -1 otherwise
ord(ch) = (strlen(ch) == 1) ? strstrt(ALLCHARS,ch): -1

# test with ASCII char 12
pr n=12, testch = sprintf('%c',n), ord(testch)

缺少NUL(ASCII码为零)字符,因为gnuplot始终没有单个字符变量类型可以容纳它,因为gnuplot字符串以NUL终止。