V
V
Viktor Familyevich2020-08-21 10:27:34
Google Apps Script
Viktor Familyevich, 2020-08-21 10:27:34

How to decode a string in Google Script?

There is a line

%u0420%u0430%u0431%u043E%u0447%u0435%u0435%20%u0432%u0440%u0435%u043C%u044F

How to code it to make it workРабочее время

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2020-08-21
@ProgrammerForever

/**
* Декодирует строку вида %uXXXX%uXXXX и/или %XX в текст
* Боев Григорий (с) 2020 (telegram @ProgrammerForever)
*
* @param {string} encoded Кодированный текст
* @return Декодированный текст
* @customfunction
*/
function uEncode(encoded) {
  return encoded.split('%')
                .filter(el=>el!='')
                .map(el=>el[0]==='u'?el.substring(1):el)
                .map(el=>parseInt(el,16))
                .map(code=>String.fromCodePoint(code))
                .join('');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question