像equalsIgnoreCase同时使用的indexOf [英] something like equalsIgnoreCase while using indexOf
本文介绍了像equalsIgnoreCase同时使用的indexOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这code,得到一个字符串的索引,在数组中。
I am using this code, to get the index of a String in an Array.
int n = Arrays.asList(Names).indexOf(textBox.getText());
是这里的问题,如果在文本框中的字符串在情况的不同在阵列的类似字符串。它返回的 1 即可。怎样才能使它像 equalsIgnoreCase 在字符串比较的情况。
The problem here is, if the String in textBox is different in case to its similar String in the Array. It returns -1. How can make it something like equalsIgnoreCase in case of String comparision.
感谢您
推荐答案
一个不同的方法,即在内部请确保忽略大小写。
A different approach where internally make sure ignore case.
public static int indexOfIgnoreCase(String[] strs, String text){
int n = strs.length;
for(int i=0;i<n;i++){
if(strs[i].equalsIgnoreCase(text))
return i;
}
return -1;
}
int n = indexOfIgnoreCase(Names,textBox.getText());
这篇关于像equalsIgnoreCase同时使用的indexOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文