是否可以检查一个字符是否匹配一个可能的列表? [英] is it possible to check if a char matches a list of possiblities?

查看:153
本文介绍了是否可以检查一个字符是否匹配一个可能的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我知道当检查字符串,你可以做类似

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 )

... ect。

推荐答案

字符串中查找 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屋!

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