在 clojure 中的字符串列表中查找子字符串

Finding a substring within a list of strings in clojure

我想查找我的字符串列表中的任何字符串中是否有子字符串。我有一个像 '("hi" "hey" "hello") 这样的列表。使用“some”我可以找到值“hi”是否在这个列表中。但是我怎么才能找到是否只有“h”在列表中的至少一个字符串中?

Clojure 解决方案:

(some #(clojure.string/includes? % "h") (list "hi" "hello" "hey"))
(some #(.contains % "h") (list "hi" "hello" "hey"))

ClojureScript 解决方案:

  • includes? 来自 clojure.string(需要 ns 形式的 clojure.string
(ns my-app.core
  (:require [clojure.string :as string]))

(some #(string/includes? % "h") (list "hi" "hello" "hey"))
(some #(.includes % "h") (list "hi" "hello" "hey"))