使用URLEncoding转换Unicode字符 [英] Using URLEncoding to Convert Unicode Characters
问题描述
我在C#中有一个带有Unicode字符(韩文字符)的字符串.
该字符串应先通过C ++,然后再传递给Java.
在C#中输入字符串会
数据源= | DataDirectory |안녕하세요.sdf
当这样传递Unicode字符串时,我得到的是?"在Java方面.我尝试使用
结果字符串是
数据+源%3d%7cDataDirectory%7c%ec%95%88%eb%85%95%ed%95%98%ec%84%b8%ec%9a%94.sdf
我的字符串被转换为%编码的UTF-8字符(如果我没记错的话).该字符串将传递给C ++,最后传递给Java.
在Java端,当我显示给User时,我在那里使用URLDecoder函数,然后又得到了朝鲜语字符.
我的问题是..这是一种处理Unicode字符的有效且正确的方法吗?还是有其他最简单的方法来解决这个问题??
更新:
我的字符串也可以有点小..其中有超过1000个字符.
最有效的方法是将字符串传递给wchar_t数组中的C ++. ,然后直接将其作为String传递给Java,因为C#和Java都在内部使用UTF-16来存储字符串. (请注意,这仅在所有三个部分都在x86/x64 CPU下时才有效,因为 它不能满足耐力)
或者,通过System.Text.Encoding.Unicode.GetBytes(InputString)将C#字符串转换为字节数组,将其作为byte []传递给C ++,并在Java端通过Charset.ForName("UTF-16LE")对其进行解码. .decode(buffer),其中 buffer 是ByteBuffer类型,如 这里.
I have a string with unicode characters in it (Korean characters) in C#.
That string should pass through C++ and then to Java.
Input String in C# wil be
Data Source=|DataDirectory|안녕하세요.sdf
When Unicode string gets passed as such i am getting '?' in the Java side. I tried to use Server.UrlEncode(InputString)
The resultant string is
Data+Source%3d%7cDataDirectory%7c%ec%95%88%eb%85%95%ed%95%98%ec%84%b8%ec%9a%94.sdf
My String gets converted to % encoded UTF-8 characters(if i m not wrong). This string will get passed to C++ and then finally to Java.
In Java side when i display in to the User i use URLDecoder function there and I get the Korean characters back..!
My question is.. Is this a efficient and correct approach to deal with Unicode Characters.? Or is there any other simplest way to handle this.?
Update:
My string can also be little big one.. with more than 1000 characters in it. Will URLEncode and Decode work under processing Huge strings tooo?
The most efficient way is to just pass the string to C++ in wchar_t array, then directly pass it to Java as String, as both C# and Java uses UTF-16 internally to store string. (Note that this only works if all three parts are under x86/x64 CPU because it does not cater for endianess)
Alternatively, convert C# string to byte array by System.Text.Encoding.Unicode.GetBytes(InputString) pass it to C++ as byte[] and decode it in Java side by Charset.ForName("UTF-16LE").decode(buffer), where buffer is ByteBuffer type as shown in here.
这篇关于使用URLEncoding转换Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!