utf-16

How to read a UTF-16 text file in C++17

不打扰是莪最后的温柔 提交于 2021-02-19 05:57:06
问题 I am very new to C++. I want to read a UTF-16 text file in C++17 in Visual Studio 2019. I have tried several methods in the internet (including StackOverflow) but none of them worked, and some of them didn't compile (I think they only support older compilers). I am trying to achieve this without using any 3rd party libraries. This reads a text file, but it has some weird characters and spaces between each letter. // open file for reading std::wifstream istrm(filename, std::ios::binary); if (

How to decode unicode string that is read from a file in Python?

烈酒焚心 提交于 2021-02-11 13:22:31
问题 I have a file containing UTF-16 strings. When I try to read the unicode, " " (double quotes) are added and the string looks like "b'\\xff\\xfeA\\x00'" . The inbuilt .decode function throws a AttributeError: 'str' object has no attribute 'decode' . I tried a few options but those didn't work. This is what the file I am reading from looks like 回答1: Try this: str.encode().decode() 回答2: It looks like the file has been created by writing bytes literals to it, something like this: some_bytes = b

How to decode unicode string that is read from a file in Python?

…衆ロ難τιáo~ 提交于 2021-02-11 13:21:35
问题 I have a file containing UTF-16 strings. When I try to read the unicode, " " (double quotes) are added and the string looks like "b'\\xff\\xfeA\\x00'" . The inbuilt .decode function throws a AttributeError: 'str' object has no attribute 'decode' . I tried a few options but those didn't work. This is what the file I am reading from looks like 回答1: Try this: str.encode().decode() 回答2: It looks like the file has been created by writing bytes literals to it, something like this: some_bytes = b

Determining text file encoding schema

僤鯓⒐⒋嵵緔 提交于 2021-02-08 05:03:35
问题 I am trying to create a method that can detect the encoding schema of a text file. I know there are many out there, but I know for sure my text file with be either ASCII , UTF-8 , or UTF-16 . I only need to detect these three. Anyone know a way to do this? 回答1: Use the StreamReader to identify the encoding. Example: using(var r = new StreamReader(filename, Encoding.Default)) { richtextBox1.Text = r.ReadToEnd(); var encoding = r.CurrentEncoding; } 回答2: First, open the file in binary mode and

How to work with UTF-16 in python ctypes?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 10:09:43
问题 I have a foreign C library which uses utf-16 in API: as function arguments, return values and structure members. On Windows its OK with ctypes.c_wchar_p, but under OSX ctypes uses UCS-32 in c_wchar and I could not find the way to support utf-16. Here is my research: Use _SimpleCData subclassing to redefine _check_retval_. it allows a transparent conversion of utf-16 to Python string. can be placed as C structure member But it doesn't allow to handle strings as arguments, its from_param()

How to work with UTF-16 in python ctypes?

萝らか妹 提交于 2021-02-07 10:09:34
问题 I have a foreign C library which uses utf-16 in API: as function arguments, return values and structure members. On Windows its OK with ctypes.c_wchar_p, but under OSX ctypes uses UCS-32 in c_wchar and I could not find the way to support utf-16. Here is my research: Use _SimpleCData subclassing to redefine _check_retval_. it allows a transparent conversion of utf-16 to Python string. can be placed as C structure member But it doesn't allow to handle strings as arguments, its from_param()

How to work with UTF-16 in python ctypes?

喜欢而已 提交于 2021-02-07 10:07:23
问题 I have a foreign C library which uses utf-16 in API: as function arguments, return values and structure members. On Windows its OK with ctypes.c_wchar_p, but under OSX ctypes uses UCS-32 in c_wchar and I could not find the way to support utf-16. Here is my research: Use _SimpleCData subclassing to redefine _check_retval_. it allows a transparent conversion of utf-16 to Python string. can be placed as C structure member But it doesn't allow to handle strings as arguments, its from_param()

I need convert UTF-16 to ANSI [closed]

本小妞迷上赌 提交于 2021-02-05 12:30:53
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago . Improve this question How i can convert UTF-16 to ANSI in a .cmd file? 回答1: Your code has a UTF-16 LE byte-order-marker at the beginning of it, which an obfuscation technique developed on DosTips. Either remove it via a hex editor, or save this code as deobfuscate.bat and drag your script onto it:

Is it possible to reliably auto-decode user files to Unicode? [C#]

*爱你&永不变心* 提交于 2021-02-04 17:34:48
问题 I have a web application that allows users to upload their content for processing. The processing engine expects UTF8 (and I'm composing XML from multiple users' files), so I need to ensure that I can properly decode the uploaded files. Since I'd be surprised if any of my users knew their files even were encoded, I have very little hope they'd be able to correctly specify the encoding (decoder) to use. And so, my application is left with task of detecting before decoding. This seems like such

Web API not able to bind model for POST with utf-16 encoded XML

走远了吗. 提交于 2021-01-27 07:09:17
问题 I have a simple Web API controller with a POST method, that accepts an object. When the clients posts data as JSON the API works fine. Even when data is sent as XML with encoding="utf-8" , the model binds seamlessly (I have added the following line in WebApiConfig to use Xml Serialization instead of DataContract ) config.Formatters.XmlFormatter.UseXmlSerializer = true; Below is my ApiController: public class InfoController : ApiController { public HttpResponseMessage Post(InfoRequest