Python UTF-16 CSV reader

At the moment, the csv module does not support UTF-16. In Python 3.x, csv expects a text-mode file and you can simply use the encoding parameter of open to force another encoding: # Python 3.x only import csv with open(‘utf16.csv’, ‘r’, encoding=’utf16′) as csvf: for line in csv.reader(csvf): print(line) # do something with the line … Read more

How does Java store UTF-16 characters in its 16-bit char type?

The answer is in the javadoc : The char data type (and therefore the value that a Character object encapsulates) are based on the original Unicode specification, which defined characters as fixed-width 16-bit entities. The Unicode standard has since been changed to allow for characters whose representation requires more than 16 bits. The range of … Read more

Correctly reading a utf-16 text file into a string without external libraries?

The C++11 solution (supported, on your platform, by Visual Studio since 2010, as far as I know), would be: #include <fstream> #include <iostream> #include <locale> #include <codecvt> int main() { // open as a byte stream std::wifstream fin(“text.txt”, std::ios::binary); // apply BOM-sensitive UTF-16 facet fin.imbue(std::locale(fin.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>)); // read for(wchar_t c; fin.get(c); ) … Read more

JavaScript strings – UTF-16 vs UCS-2?

JavaScript, strictly speaking, ECMAScript, pre-dates Unicode 2.0, so in some cases you may find references to UCS-2 simply because that was correct at the time the reference was written. Can you point us to specific citations of JavaScript being “UCS-2”? Specifications for ECMAScript versions 3 and 5 at least both explicitly declare a String to … Read more

How to solve “unable to switch the encoding” error when inserting XML into SQL Server

This question is a near-duplicate of 2 others, and surprisingly – while this one is the most recent – I believe it is missing the best answer. The duplicates, and what I believe to be their best answers, are: Using StringWriter for XML Serialization (2009-10-14) https://stackoverflow.com/a/1566154/751158 Trying to store XML content into SQL Server 2005 … Read more