ML语言的cdr字符串

时间:2011-11-25 08:27:25

标签: ml

我试图在ML中找到一个等于({1}}中的(cdr string)的库函数(意思是(cdr abcd)= bcd)。

2 个答案:

答案 0 :(得分:1)

(假设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参数使其提取直到字符串结束。

答案 1 :(得分:0)

假设使用Ocaml方言,您可以使用标准String模块,例如。

let rest_str str = 
  let slen = String.length str in
  String.sub str 1 (slen-1)
;;