当前位置: 首页 > 文档资料 > Clojure 中文教程 >

subs

优质
小牛编辑
118浏览
2023-12-01

返回's'的子字符串,从开始包含开始,到结尾结束(默认为字符串的长度),不包括。

语法 (Syntax)

以下是语法。

(subs s start end)

Parameters - 'S'是输入字符串。 'Start'是从哪里开始子串的索引位置。 'End'是结束子字符串的索引位置。

Return Value - 子字符串。

例子 (Example)

以下是Clojure中字符串格式的示例。

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println (subs "HelloWorld" 2 5))
   (println (subs "HelloWorld" 5 7)))
(hello-world)

输出 (Output)

上述程序产生以下输出。

llo
Wo