gpt4 book ai didi

string - 检查 clojure 中的字符串是否包含子字符串

转载 作者:行者123 更新时间:2023-12-02 09:43:59 25 4
gpt4 key购买 nike

我需要检查 java 字符串在我的测试中是否包含子字符串。

这不起作用,因为 java 字符串不是集合:

(deftest test_8
(testing "get page from sputnik"
(let [
band "Isis"
page (get-sputnikpage-for-artist band)
]
(is (contains? band "Isis")))));does NOT work

有没有办法将java字符串转换为集合?或者我可以通过其他方式检查子字符串的出现吗?

最佳答案

最简单的方法是使用 java.lang.String 中的 contains 方法:

(.contains "The Band Named Isis""Isis")

=> 正确

您也可以使用正则表达式来实现,例如

(re-find #"Isis" "The Band Named Isis")

=>“伊斯兰国”

(re-find #"Osiris" "The Band Named Isis")

=> 无

如果您需要结果为 true 或 false,可以将其包装在 boolean 中:

(boolean (重新查找 #"Osiris""The Band Named Isis"))

=> 假

关于string - 检查 clojure 中的字符串是否包含子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26386766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com