Java:如何从字符串“\u00C3”创建unicode ETC
我有一个文件,其中的字符串手写为 \u00C3。我想创建一个由 java 中的 unicode 表示的 unicode 字符。我尝试过但找不到方法。帮助。
编辑:当我读取文本文件字符串时,将包含“\u00C3”,不是 unicode,而是 ASCII 字符 '\' 'u' '0' '0' '3'。我想从该 ASCII 字符串形成 unicode 字符。
I have a file that has strings hand typed as \u00C3. I want to create a unicode character that is being represented by that unicode in java. I tried but could not find how. Help.
Edit: When I read the text file String will contain "\u00C3" not as unicode but as ASCII chars '\' 'u' '0' '0' '3'. I would like to form unicode character from that ASCII string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在网络上的某个地方找到了这个:
I picked this up somewhere on the web:
哎呀,我有点慢了。这是我的解决方案:
Dang, I was a bit slow. Here's my solution:
StringEscapeUtils.unescapeJava 工作正常:)
请参阅: https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#unescapeJava( java.lang.String)
StringEscapeUtils.unescapeJava work fine:)
see: https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringEscapeUtils.html#unescapeJava(java.lang.String)
如果您只想转义 unicode 而不想转义其他内容,可以通过编程方式创建一个函数:
这使用 org.apache.commons.text.translate.UnicodeUnescaper。
If you want to escape only unicode and nothing else, programmatically, you can create a function:
This uses org.apache.commons.text.translate.UnicodeUnescaper.
大概是这样的:
Probably something along the lines: