【发布时间】:2019-04-18 14:30:50
【问题描述】:
我有一个 NSFW 类,可以根据已知 NSFW 单词列表扫描项目名称和描述等文本。
这将是测试字符串列表的最佳方法
let nsfw = listof(
"badword",
"curseword",
"ass",
... 200+ more
)
针对如下字符串:
This is the text that contains a badword // returns true
请注意,我需要检查完整的单词。不是单词的一部分。
所以那句话:
The grass is grean // returns false
因为草不是一个坏词。
我尝试过类似的方法,但它不检查完整的单词。
val result = nsfw.filter { it in sentence.toLowerCase() }
【问题讨论】: