这个维基页面提供了如何将单个字符串转换为ascii的一般概念http://en.wikibooks.org/wiki/Ruby_Programming/ASCII
但是说如果我有一个字符串并且我想从中获取每个字符的ascii,我需要做什么?
"string".each_byte do |c|
$char = c.chr
$ascii = ?char
puts $ascii
end
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为它对行$ ascii =?char不满意
syntax error, unexpected '?'
$ascii = ?char
^
Run Code Online (Sandbox Code Playgroud)