是否有可能检查一个字符是否匹配可能性列表? [英] is it possible to check if a char matches a list of possibilities?
本文介绍了是否有可能检查一个字符是否匹配可能性列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我知道在检查字符串时,您可以执行类似
For example I know that when checking strings, you can do something like
if (string.matches("a|e|i|o|u|A|E|I|O|U" ) )
{
// Then do this code.
}
但有没有办法检查char是否与可能性列表相匹配?
或者我必须逐个检查,例如
but is there a way to check if a char matches a list of possibilities? or do I have to check one by one, such as
if(char == a || char == e || char == i )
...等等。
推荐答案
在字符串中查找
,使用 char
时,您可以执行类似操作 indexOf
方法搜索字符串。
You can do something similar when looking for a char
in a String
, by using the indexOf
method to search the string.
if ("aeiouAEIOU".indexOf(aChar) != -1)
这篇关于是否有可能检查一个字符是否匹配可能性列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文