我将toLocaleLowerCase()用作拉丁字符。拉丁字符是“Ö”。我首先对其进行编码,然后尝试使用toLocaleLowerCase()使其小写。似乎没有给我正确的小写字符

const encodedText: string = encodeURIComponent("Å"); --> value is "%C3%85"
const lowerCaseText: string = encodedText.toLocaleLowerCase(); --> value is "%c3%85". But it should be "%C3%A5"


这是怎么了
它与浏览器的语言环境有关吗?
我怎样才能解决这个问题?

最佳答案

您正在做的顺序是错误的。

您要先使用toLocaleLowerCase,然后再使用encodeURIComponent。否则,它将更改编码字符串的大小写,而不是字符串本身。



var char = "Å";
console.log(encodeURIComponent(char));

var lowerCaseChar = char.toLocaleLowerCase();
console.log(encodeURIComponent(lowerCaseChar));

09-26 20:55