[英]Special char not recognized in String class
我已经工作算法逻辑计算器和一些常用接受逻辑字符没有被由String类检测(即⇔
未检测到时String.indexOf("⇔");
被称为)
我能够创建一个解决方案,并将其发布在这里以帮助其他有类似问题的人。
/*
* Compares the decimal value of each char to the decimal value of the char
* that isn't detected by java.String
*/
String string = "any char with ⇔ decimal value";
int[] charAsDecimal = new int[string.length() -1];
int locationOfSpeicalChar = 0;
for(int x = 0; x < string.length(); x++)
{
charAsDecimal[x] = (int)string.charAt(x);
}
for(int x = 0; x < string.length(); x++)
{
if(charAsDecimal[x] == 8660)
{
System.out.println("⇔ is at index value " + x);
locationOfSpeicalChar = x;
}
}
System.out.println(string);
string = string.substring(locationOfSpeicalChar);
System/out.println(string);
/*
* ⇔ in decimal is 8660 and can be used to find in charAsDecimal. The index value
* in charAsDecimal is the same index value as in string.
*/
首先,没有必要写string.length()-1
,用这种方法你会丢失一个字符
其次,我不知道这段代码中的E
是什么,这里没有定义,可能你需要将char
数组转换为int
数组,试试这种方式:
String string = "any char with decimal value";
int[] a = new int[string.length()];
for(int x = 0; x < string.length() ; x++){
a[x] = (int)string.charAt(x);
System.out.println("value at " + x + " : " + string.charAt(x) + " in dec = " + a[x]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.