Fastest way to encode cyrillic letters for url

前端 未结 2 994
旧时难觅i
旧时难觅i 2021-02-07 10:33

If you copy the link below into the browser

http://be.wikipedia.org/wiki/Беларусь 

it will show the Wiki article. But once you want to copy th

相关标签:
2条回答
  • 2021-02-07 11:05

    I guess encodeURI(string) should be what you are looking for. Just check out already existing answers to the same question e.g. here!

    0 讨论(0)
  • 2021-02-07 11:19

    The function you're searching for is encodeURIComponent.

    encodeURIComponent("Беларусь");
    // returns "%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D1%8C"
    

    Its counterpart is decodeURIComponent which reverses this process.

    decodeURIComponent("%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D1%8C");
    // returns "Беларусь"
    
    0 讨论(0)
提交回复
热议问题