PASCAL字符串到数组 [英] PASCAL string to array
本文介绍了PASCAL字符串到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
帕斯卡,我如何转动(读取)诸如数字 21354561321535613的字符串成数字并将其存储在数组?
Pascal, How can i turn (read) a string of numbers like for example '21354561321535613' into digits and stock them in an array ?
推荐答案
您可以通过减去序号'0'<轻松地将数字转换为整数/ code>。循环执行此操作,每个数字都有一个整数:
You can easily turn a digit into an integer by subtracting the ordinal value of '0'
. Do this in a loop and you have an integer for each digit:
var
S: string;
A: array of Integer;
I, Len: Integer;
begin
S := '21354561321535613';
Len := Length(S);
{ Reserve Len Integers. }
SetLength(A, Len);
{ Convert each digit into an integer: }
for I := 1 to Len do
A[I - 1] := Ord(S[I]) - Ord('0'); { [I - 1] because array is zero-based. }
end;
这篇关于PASCAL字符串到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文