Java中的IDNA的常规字符串 [英] Regular String to IDNA in Java
本文介绍了Java中的IDNA的常规字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
java.net.IDN 似乎做的伎俩。从我的Scala控制台:
scala> java.net.IDN.toUnicode(xn--9dbne9b.com)
res0:java.lang.String =שלום。com
请注意,它适用于主机名,而不是URL。所以你必须先删除/解压缩 http://
协议。
快速浏览文档显示它的工作方向也是相反的。从上面(我的Unicode主机名在变量 res0
)
scala> java.net.IDN.toASCII(res0)
res3:java.lang.String = xn--9dbne9b.com
Is there a library that is able to parse Unicode domain name into IDNA? Like שלום.com ==> http://xn--9dbne9b.com/ ?
解决方案
java.net.IDN seems to do the trick. From my Scala console:
scala> java.net.IDN.toUnicode("xn--9dbne9b.com")
res0: java.lang.String = שלום.com
Note that it works on the hostname, not the URL. So you'll have to strip/extract the http://
protocol first.
A quick glance at the documentation reveals it works in the opposite direction too. From above (my Unicode hostname in the variable res0
)
scala> java.net.IDN.toASCII(res0)
res3: java.lang.String = xn--9dbne9b.com
这篇关于Java中的IDNA的常规字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文