【问题标题】:Unicode Right To Left Override Character is not working for reversing a string in Java8Unicode 从右到左覆盖字符不适用于在 Java 8 中反转字符串
【发布时间】:2020-11-12 23:17:19
【问题描述】:
public class ReverseStringUnicodeRightToLeftOverrideCharacter {

    public static String reverse(String str)
        {
            
              return '\u202E' + str;
        }
        public static String reverse(String str)
        {
            //return "\u202D" + str;
              return '\u202E' + str;
        }
public static void main (String[] args)
        {
            
"\u202E" + str  is not working in Java

String str = "Techie Delight";
str = reverse(str);

System.out.println("Reverse of the given string is : " + str); 
            
                  
    }
}

为此,我得到以下输出:

Reverse of the given string is : ?Techie Delight

【问题讨论】:

标签: java string


【解决方案1】:

你必须像这样连接它:

public static String reverse(String str)
    {
        return "\u202E"+str+"\u202D";
    }

将“\u202E”作为字符串而不是开头的字符,将字符串末尾的“\u202D”反转。

【讨论】:

  • 你提到的解决方案是给我下面的输出:给定字符串的反转是:?Techie Delight?
  • public class ReverseString { public static String reverse(String str) { //return "\u202D" + str; //返回 '\u202E' + str;返回 "\u202E"+str+"\u202D"; } public static void main (String[] args) { String str = "Techie Delight"; //byte[] bytes = str.getBytes(StandardCharsets.UTF_8); //String utf8EncodedString = new String(bytes, StandardCharsets.UTF_8); //utf8EncodedString = reverse(utf8EncodedString); str = 反向(str); System.out.println("给定字符串的反转是:" + str); }}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-13
  • 2018-02-03
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
相关资源
最近更新 更多