我想查找我的字符串列表中的任何字符串中是否有子字符串。我有一个像'(“hi”“hey”“hello”)这样的列表。使用“some”我可以找到值“hi”是否在此列表中。但是我怎样才能找到列表中的至少一个字符串中是否只有“h”呢?
Clojure解决方案:
includes?从clojure.string(some #(clojure.string/includes? % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)
contains通过 Java 互操作(some #(.contains % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)
ClojureScript 解决方案:
includes?来自(表格中clojure.string要求)clojure.stringns(ns my-app.core
(:require [clojure.string :as string]))
(some #(string/includes? % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)
includes通过 JavaScript 互操作(some #(.includes % "h") (list "hi" "hello" "hey"))
Run Code Online (Sandbox Code Playgroud)