var
str : string
n = 20013
1.迭代器:
iterator pos( num : int): string =
var tmp = num
while tmp != 0:
yield $(tmp mod 10)
tmp = tmp div 10
2.将数字转换为字符串,再访问
for i in $n:
echo i
var
str : string
n = 20013
iterator pos( num : int): string =
var tmp = num
while tmp != 0:
yield $(tmp mod 10)
tmp = tmp div 10
for i in $n:
echo i
本文标题:获取数字的各个位
本文链接:https://www.haomeiwen.com/subject/mstgpctx.html
网友评论