ML 语言中的 cdr 字符串

发布于 2024-12-17 17:38:34 字数 99 浏览 6 评论 0原文

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

I try to find a library function in ML that equal to (cdr string) in Scheme (meaning (cdr abcd) = bcd).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

手心的海 2024-12-24 17:38:34

(假设 SML)

另一种方法是将字符串转换为字符列表(爆炸),然后你可以选择拿走头部(hd) 或 tail (tl),然后最后将其转换回字符串(implode):

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

字符串转换函数可以在 < a href="http://www.standardml.org/Basis/string.html" rel="nofollow">String 模块,head 和 tail 函数可以在 List 模块

显然你也可以在这里使用 substring 方法,但是在 SML 中你有 extract 函数在这种情况下非常方便:

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

给它 <代码>无参数使其提取直到字符串末尾。

(Asuming SML)

Another way is to convert the string to a list of chars (explode), then you have the option to take the head (hd) or tail (tl), and then finally convert it back to a string (implode):

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

The string conversion functions can be found in the String module, and the head and tail functions can be found in the List module

Obviously you can also use the substring method here, however in SML you have the extract function that are quite convenient in this case:

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

Giving it the NONE argument makes it extract until the end of the string.

下雨或天晴 2024-12-24 17:38:34

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

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

Assuming the Ocaml dialect, you could use the standard String module with e.g.

let rest_str str = 
  let slen = String.length str in
  String.sub str 1 (slen-1)
;;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文