首页 > 解决方案 > toLocaleLowerCase() 的使用

问题描述

我正在使用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"

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

标签: javascripttypescript

解决方案


你正在做的事情的顺序是错误的。

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

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

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


推荐阅读