检查字符串是否为毫升中的数字

问题描述 投票:0回答:1

有人可以帮我编写一个实现该功能的函数吗?我试过了:

fun isPascalInteger (s:string) = if (size(s)=0) then return true
    else if (!(isDigit(sub(s,0)))) then return false
    else (isPascalInteger(extract(s,1)));
sml ml
1个回答
0
投票

最方便的使用字符串的方法通常是先转换为列表,然后使用列表功能:

fun isPascalInteger (s:string) = List.all Char.isDigit (explode s)
© www.soinside.com 2019 - 2024. All rights reserved.