2011-11-25 54 views

回答

1

(Asuming SML)

另一种方式是将字符串转换为(explode)字符的列表,那么你必须搭头(hd)或尾部(tl)的选项,然后最终将其转换回一个字符串(implode):

- (implode o tl o explode) "this is a string"; 
val it = "his is a string" : string 

的字符串转换函数可以将String模块中找到,且头部和尾部功能可以在中找到模块

很明显,你也可以在这里使用的子方法,但是在SML你有extract功能非常方便在这种情况下:

- String.extract("This is a string", 1, NONE); 
val it = "his is a string" : string 

给它NONE参数使得其解压缩,直到结束的字符串。

0

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

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