[英]Not able to decode unicode of Currency Symbol when passed as environment variables
以下代码适用于卢比符号。
String encode ="\u20B9";
byte[] ptext = encode.getBytes(StandardCharsets.UTF_8);
String value = new String(ptext,StandardCharsets.UTF_8);
System.out.print(value);
It prints : ₹
但是当我们将Rupee Symbol unicode作为环境变量传递时,它不起作用
String encode = System.getenv("encode");
byte[] ptext = encode.getBytes(StandardCharsets.UTF_8);
String value = new String(ptext,StandardCharsets.UTF_8);
System.out.print(value);
It prints : \u20B9
这个我试过mac OS。
Java只在Java源文件中处理它时才理解\\uXXXX
格式,并且编译器处理它(解析它并将其转换为单个字符)。 如果从某处读取值,则不会将其解释为unicode字符(除了.properties文件,这有点特殊)。
₹
字符 粘贴实际
₹
字符而不是使用\\u\u003c/code>转义,如Kayaman的正确答案中所述。
适用于IntelliJ 2018.2.2中的macOS High Sierra和Java 10.0.1 ( Zulu by Azul Systems )。
package com.basilbourque.example;
public class Env {
// Example passing Unicode characters via system environment variable.
public static void main ( String[] args ) {
System.out.println( "Bonjour tout le monde." );
System.out.println( System.getProperty( "java.version" ) );
System.out.println( System.getenv( "wazzup" ) );
System.out.println( System.getenv( "fire" ) );
System.out.println( System.getenv( "rupee" ) );
}
}
Bonjour tout le monde。
10.0.1
午餐
🔥
₹
UnicodeChecker应用程序
提示:您可以在优秀的免费macOS应用程序UnicodeChecker中查找并复制所有Unicode字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.