[英]Merging/Combining a list of Integers with Char [Haskell]
I'd like a hint on how to apply this function: 我想知道如何应用这个功能:
dti xs = (map intToDigit (take 6 (map digitToInt xs))++['/']++map intToDigit(drop 6 (map digitToInt xs)))
on a list of Integers, eg; 在整数列表中,例如; [1234567822,3245336792,...], so I'd get an output like ["123456/7822","324533/6792",...].
[1234567822,3245336792,...],所以我得到的输出像[“123456/7822”,“324533/6792”,...]。
The point is to add a "/" after the 6th digit in each number of a list of integers, eg; 重点是在整数列表的每个数字的第6位之后添加“/”,例如; [1234567822,3245336792,...].
[1234567822,3245336792,...]。 Maybe there's a better way to do it than mine.
也许有比这更好的方法。
intToDigit
expects a single digit, so it will raise an error on input like 1234567822. intToDigit
需要一个数字,所以它会引起输入错误,如1234567822。
To convert an Int
(or Integer
) into a list of characters, you can use show
, and then split the resulting string after six digits 要将
Int
(或Integer
)转换为字符列表,可以使用show
,然后将结果字符串拆分为六位数
format n = first ++ '/':second
where
s = show n
(first,second) = splitAt 6 s
dti = map format
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.