EN
TypeScript - convert string to lowercase
0 points
In this quick article, we are going to discuss how to convert string to lower case in TypeScript. String class contains two methods that help to make the conversion to lower case. One of them allows making conversion by taking into account locale. To see practical usage of methods look at the below examples.
With this approach, it is possible to convert any string to lower case.
xxxxxxxxxx
1
const text: string = 'Hi! How are you?';
2
const convertedText: string = text.toLowerCase();
3
4
console.log(convertedText);
Output:
xxxxxxxxxx
1
hi! how are you?
This section shows how to convert any string to lower case taking into account locale. In almost all cases it produces a similar output string to version without locale.
xxxxxxxxxx
1
const text: string = 'Здравствуй! Как поживаете?';
2
3
const convertedText: string = text.toLocaleLowerCase();
4
// const convertedText: string = text.toLocaleLowerCase('ru-RU');
5
// const convertedText: string = text.toLocaleLowerCase(['ru-RU', 'en-US']);
6
7
console.log(convertedText);
Output:
xxxxxxxxxx
1
здравствуй! как поживаете?