问题描述
问题的变化。
我想找到一个字符串的字符是波斯语和英语字符。
i wanna find that an character in a String is Persian or English char.
在codeS搜索后,我发现这code在 PHP
: VAR UCS2 = text.search(/ [ ^ \\ x00- \\ x7D] /)= -1
可以在串放搜索;当发现是不等于UCS2价值的特性,返回-1;
after search in codes, i find that this code in PHP
: var ucs2 = text.search(/[^\x00-\x7D]/) =-1
can search in an string & when find a character that was not equal to value of ucs2 , return -1 ;
什么是现在等于在Java和放这个命令code;的android?
我怎么可以在一个字符串搜索字符没有为
循环播放
&安培; 字符的数组
?
now what is equal to this command code in java & android?how i can search a character in a string without a for
Loop
& a array of character
?
推荐答案
这可能会帮助你...
this may help you...
它搜索基础上的ASCII code字符串中的字符。因此,你可以在很多语言使用...
It searches for a character in String based on it's ASCII code. thus you can use in many languages...
private static int searchCharacter(String string, char ch) {
final int chASCII = (int) ch;
return seachCharacter(string, chASCII);
}
private static int seachCharacter(String string, int chASCII) {
if (string == null || string.isEmpty()) {
return -1;
}
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
int cASCII = (int) c;
if (chASCII == cASCII) {
return i; // found at index i
}
}
return -1;
}
这篇关于在字符串值搜索字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!