[英]Is there any way to convert a String variable into a Char
I'm asking if is there a way to convert a unit of a string into a char?我在问是否有办法将字符串的单位转换为字符? to be more clear, is there a way to legalize this instruction:更清楚的是,有没有办法使这条指令合法化:
var
s : String;
begin
s:='stackoverflow';
ord(s[1]); // Illegal expression
end.
Getting the ASCII code from one unit of a string ( which has to be a char ) demanded a complicated algorithm in Object Pascal, can I do it in an easier way?从一个字符串单元(必须是 char )中获取 ASCII 代码需要在 Object Pascal 中使用复杂的算法,我可以用更简单的方法来完成吗?
You can't use Ord(s[1])
as its own statement like you are, but you can use it as an expression within a larger statement, eg:你不能像你一样使用Ord(s[1])
作为它自己的语句,但你可以将它用作更大语句中的表达式,例如:
var
s : String;
i: Integer;
begin
s := 'stackoverflow';
i := Ord(s[1]); // i = 115
end.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.