V
V
vovashaplin2020-12-19 20:33:14
C++ / C#
vovashaplin, 2020-12-19 20:33:14

How to convert ANSI to UTF-16 LE?

How to convert ANSI to UTF-16 LE ( little_endian) ?
We need a way to translate into any of these languages.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Dubrovin, 2020-12-19
@vovashaplin

little endian - after each ASCII character, insert a character with code 0. big endian - before each ASCII character, insert a character with code 0.

F
freeExec, 2020-12-19
@freeExec

var buffer = Encoding.Unicode.GetBytes("Привет");

R
res2001, 2020-12-19
@res2001

In WinAPI , MultiByteToWideChar is available for all languages.

V
Vasily Bannikov, 2020-12-26
@vabka

var asciiBytes = File.ReadAllBytes(fileName); // допустим, что мы читаем текст из файла.

var text = Encoding.ASCII.GetString(asciiText); // Переводим байты ASCII в текст
var utf16leBytes = Encoding.Unicode.GetBytes(text); // Переводим текст в байты UTF-16LE

You may not need Encoding.ASCII, but Encoding.GetEncoding(1251), for example, if you really need win-1251.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question