【发布时间】:2017-12-10 15:42:55
【问题描述】:
我尝试在ML 中找到一个库函数,它等于Scheme 中的(cdr 字符串)(意思是 (cdr abcd) = bcd)。
【问题讨论】:
标签: ml
我尝试在ML 中找到一个库函数,它等于Scheme 中的(cdr 字符串)(意思是 (cdr abcd) = bcd)。
【问题讨论】:
标签: ml
(假设 SML)
另一种方法是将字符串转换为字符列表(explode),然后您可以选择取头部(hd)或尾部(tl),最后再转换回一个字符串(implode):
- (implode o tl o explode) "this is a string";
val it = "his is a string" : string
字符串转换函数可以在String模块中找到,head和tail函数可以在List模块中找到
显然你也可以在这里使用 substring 方法,但是在 SML 中你有 extract 函数,在这种情况下非常方便:
- String.extract("This is a string", 1, NONE);
val it = "his is a string" : string
给它NONE 参数使其提取到字符串的末尾。
【讨论】:
假设使用 Ocaml 方言,您可以使用标准的 String 模块,例如
let rest_str str =
let slen = String.length str in
String.sub str 1 (slen-1)
;;
【讨论】: