The easiest way is to simply open the file as UTF-16LE in the first place:
register_mark = "\00ua3"
File.open('C:/Output.txt', 'wt', encoding: 'UTF-16LE') do |f|
f.puts register_mark
end
The important thing here is to explicitly indicate the encoding of the file using the key :encodingin the options Hashmethod File.new(or in this case File.open). Thus, the lines written to the file will be converted automatically, regardless of what encoding they are in.
Ruby:
- Ruby
snake_case, CamelCase . - , , .
Array#pack, , .File.open, , .t. (, , ), Windows, , , , .