Answer the question
In order to leave comments, you need to log in
Saving csv file in windows-1251, javascript?
Hello
, I am saving the file with data:text/csv;charset=windows-1251,некий текст
.
The file is encoded in utf-8 .
" some text " is also processed encodeURI
, tried without it, the result did not change.
The file needs to be saved in windows-1251 encoding .
Thanks in advance .
Answer the question
In order to leave comments, you need to log in
Kano , Thanks for the first link.
You just need to translate "some text" that I put in the file into a link with windows-1251 encoding . I took https://github.com/mathiasbynens/windows-1251
as a basis and added it.
var encodeURL = function(input) {
var length = input.length;
var index = -1;
var codePoint;
var pointer;
var result = '';
while (++index < length) {
codePoint = input.charCodeAt(index);
// “If `code point` is in the range U+0000 to U+007F, return a byte whose
// value is `code point`.”
if (codePoint >= 0x00 && codePoint <= 0x7F) {
result += '%' + (codePoint<16?'0':'') + codePoint.toString(16);
continue;
}
// “Let `pointer` be the index pointer for `code point` in index
// `single-byte`.”
if (hasOwnProperty.call(INDEX_BY_CODE_POINT, codePoint)) {
pointer = INDEX_BY_CODE_POINT[codePoint];
// “Return a byte whose value is `pointer + 0x80`.”
result += '%' + (codePoint<16?'0':'') + (pointer + 0x80).toString(16);
} else {
// “If `pointer` is `null`, return `error` with `code point`.”
result += error(codePoint, mode);
}
}
return result.toUpperCase();
};
Utf8 Because habrahabr.ru/post/17640
And in order to get windows-1251, your first line must be encoded using a third-party library for universalism, for example https://github.com/mathiasbynens/windows-1251 or if you are on chrome, you can https:/ /developer.mozilla.org/en-US/docs/Web/API/T...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question