EN
TypeScript - convert string to uppercase
0 points
In this quick article, we are going to discuss how to convert string to upper case in TypeScript. String class contains two methods that help to make the conversion to upper case. One of them allows making conversion by taking into account locale. To see practical usage of methods look at the below examples.
This section shows how to convert any string to upper case taking into account locale. In almost all cases it produces a similar output string to version without locale.
xxxxxxxxxx
1
const text: string = 'Hi! How are you?';
2
const convertedText: string = text.toUpperCase();
3
4
console.log(convertedText);
Output:
xxxxxxxxxx
1
HI! HOW ARE YOU?
This section shows how to convert any string to upper 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.toLocaleUpperCase();
4
//const convertedText = text.toLocaleUpperCase('ru-RU');
5
//const convertedText = text.toLocaleUpperCase(['ru-RU', 'en-US']);
6
7
console.log(convertedText);
Output:
xxxxxxxxxx
1
ЗДРАВСТВУЙ! КАК ПОЖИВАЕТЕ?