gpt4 book ai didi

javascript url 解码不起作用

转载 作者:行者123 更新时间:2023-11-28 15:57:48 26 4
gpt4 key购买 nike

我的字符串是;

var str = "Mehmet%2bAli%2b%c3%96zcan";

我想获取字符串;

var strDecoded = "Mehmet Ali Özcan";

我尝试了以下所有方法;

strDecoded = decodeURIComponent(str); // Fails;
strDecoded = decodeURIComponent((str + '').replace(/\+/g, '%20')); // Fails
strDecoded = _decodeURI(str); // Fails


function _decodeURI(str) {
str = decodeURI(str);
str = str.replace(/%27/g, "'");
return str;
}

我还能做什么来获得正确的字符串?有什么想法吗?

最佳答案

以下内容对我有用:

decodeURIComponent("Mehmet%2bAli%2b%c3%96zcan").replace(/\++/g, ' ');

关于javascript url 解码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18017067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com