在字符字面值中有太多的字符(代理字符)

huangapple 未分类评论62阅读模式
标题翻译

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"

huangapple
  • 本文由 发表于 2020年3月16日 14:52:40
  • 转载请务必保留本文链接:https://java.coder-hub.com/60701485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定