使用 .contains 方法忽略大小写的选项? [英] Option to ignore case with .contains method?

查看:35
本文介绍了使用 .contains 方法忽略大小写的选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 .contains() 方法忽略大小写?

Is there an option to ignore case with .contains() method?

我有一个 DVD 对象的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆