使用.contains方法忽略大小写的选项? [英] Option to ignore case with .contains method?
问题描述
是否可以选择忽略 .contains()
方法的情况?
Is there an option to ignore case with .contains()
method?
我有一个<$ DVD对象的c $ c> ArrayList 。每个DVD对象都有一些元素,其中一个是标题。我有一个搜索特定标题的方法。它有效,但我希望它不区分大小写。
I have an ArrayList
of DVD object. Each DVD object has a few elements, one of them is a title. And I have a method that searches for a specific title. It works, but I'd like it to be case insensitive.
推荐答案
我猜你的意思是在用字符串搜索时忽略大小写?
I'm guessing you mean ignoring case when searching in a string?
我不知道,但您可以尝试将字符串转换为搜索到较低或大写,然后搜索。
I don't know any, but you could try to convert the string to search into either to lower or to upper case, then search.
// s is the String to search into, and seq the sequence you are searching for.
bool doesContain = s.toLowerCase().contains(seq);
编辑:
正如Ryan Schipper建议的那样,你也可以(也可能会更好) )根据你的情况做seq.toLowerCase()。
As Ryan Schipper suggested, you can also (and probably would be better off) do seq.toLowerCase(), depending on your situation.
这篇关于使用.contains方法忽略大小写的选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!