L
L
LittleFatNinja2015-07-31 11:47:27
JavaScript
LittleFatNinja, 2015-07-31 11:47:27

How to decode an escape string?

there is a string "hello", as I understand it, in windows encoding 1251
%EF%F0%E8%E2%E5%F2
I get:
Uncaught URIError: URI malformed
the problem is that decodeURI ( ) accepts utf-8
, help me, how to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2015-07-31
@LittleFatNinja

In general, of course, it is strange that browsers capable of displaying a page in most encodings, including data: text/plain; charset=cp1251,% EF% F0% E8% E2% E5% F2, do not allow using their capabilities in javascript. FileReader has a readAsText method that takes an encoding as the second parameter, but I still haven’t figured out what the readable Blob should be.
If there is no desire to use libraries, you can decode in the forehead

var cp1251 = 'ЂЃ‚ѓ„…†‡€‰Љ‹ЊЌЋЏђ‘’“”•–—�™љ›њќћџ ЎўЈ¤Ґ¦§Ё©Є«¬­®Ї°±Ііґµ¶·\
ё№є»јЅѕїАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя';
var str = '%EF%F0%E8%E2%E5%F2'.replace(/%(..)/g, function(s, p) {
    p = parseInt(p, 16);
    return p < 128 ? String.fromCharCode(p) : cp1251[p - 128];
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question