标题翻译
To many characters in character literal (surrogate characters)
问题
I'm facing this error
> To many caracters in character literal.
I know a similar question was already answered. Plz help me with this because that answer does not work for me.
Here is my code
case 1:
for (int charOne = 0; charOne <= strBld.length() - 1; charOne++) {
char a = strBld.charAt(charOne);
char newCh = getCharOne(a);
strBld.setCharAt(charOne, newCh);
}
break;
This is working fine.
private char getCharOne(char a){
char ch = a;
if (ch == 'B' || ch == 'b') {
ch = '๒';
}
return ch;
}
But now I want to use this (surrogate characters)
🅐
when I paste it converts into \uD83C\uDD50 this format and an error shown To many characters in character literal
private char getCharOne(char a){
char ch = a;
if (ch == 'A' || ch == 'a') {
ch = '\uD83C\uDD50';
}
return ch;
}
英文翻译
I'm facing this error
> To many caracters in character literal.
I know a similar question was already answered. Plz help me with this because that answer does not work for me.
Here is my code
case 1:
for (int charOne = 0; charOne <= strBld.length() - 1; charOne++) {
char a = strBld.charAt(charOne);
char newCh = getCharOne(a);
strBld.setCharAt(charOne, newCh);
}
break;
This is working fine.
private char getCharOne(char a){
char ch = a;
if (ch == 'B' || ch == 'b') {
ch = '๒';
}
return ch;
}
But now I want to use this (surrogate characters)
🅐
when i paste it converts into \uD83C\uDD50 this format and an error shown To many characters in character literal
private char getCharOne(char a){
char ch = a;
if (ch == 'A' || ch == 'a') {
ch = '\uD83C\uDD50';
}
return ch;
}
答案1
得分: 0
你不能在 ' ' 中写入多于一个字符的内容。你已将 ch 定义为字符,因此无法将字符串赋值给它。
你应该再定义另一个变量作为字符串,并将 \uD83C\uDD50 赋值给它。
例如:
var a: String
a = "\uD83C\uDD50"
英文翻译
You can't write more than one character in ' '. You have defined ch as character so
you can't give string to it
You should define another variable as string and give \uD83C\uDD50 to it.
for example:
var a:String
a="\uD83C\uDD50"
专注分享java语言的经验与见解,让所有开发者获益!
评论