是否可以检查字符是否与可能性列表匹配? [英] 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.
}
但是有没有办法检查字符是否与可能性列表匹配?还是要一一检查,比如
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 )
...等
推荐答案
在 String
中查找 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屋!
查看全文