Js letter case conversion implementation method summary

  • 2020-03-29 23:40:29
  • OfStack

ToLocaleUpperCase method

Returns a string in which all alphabetic characters are converted to uppercase while accommodating the current locale of the host environment.
StringVar. TolocaleUpperCase ()
The required stringVar reference is a String object, value, or literal.

instructions
The toLocaleUpperCase method converts the characters in the string while accommodating the current locale of the host environment. In most cases, the result is the same as that obtained using the toUpperCase method. However, if the language rules conflict with the normal Unicode case mapping, the result can be different.

ToLocaleLowerCase method

Returns a string in which all alphabetic characters are converted to lowercase, taking into account the current locale of the host environment.
StringVar. TolocaleLowerCase ()
The required stringVar reference is a String object, value, or literal.

instructions
The toLocaleLowerCase method converts the characters in the string while adapting to the current locale of the host environment. In most cases, the results are the same as those obtained using the toLowerCase method. However, if the language rules conflict with the normal Unicode case mapping, the result can be different.

ToLowerCase method

Returns a string whose letters are converted to lowercase letters.
StrVariable. ToLowerCase ()
"String Literal" toLowerCase ()

instructions
The toLowerCase method does not affect non-alphabetic characters.

The following example demonstrates the effect of the of the toLowerCase method:
Var strVariable = "This is a STRING object";
StrVariable = strVariable. ToLowerCase ();

The value of strVariable after the last statement is:
This is a string object

Method toUpperCase

Returns a string in which all letters are converted to uppercase.
StrVariable. ToUpperCase ()
"String Literal" toUpperCase ()

instructions
The toUpperCase method has no effect on non-alphabetic characters.

The sample
The following example demonstrates the effect of the toUpperCase method:
Var strVariable = "This is a STRING object";
StrVariable = strVariable. ToUpperCase ();

The value of strVariable after the last statement is:
THIS IS A STRING OBJECT


function UpperFirstLetter(str)   
{   
    return str.replace(//b/w+/b/g, function(word) {   
                           return word.substring(0,1).toUpperCase( ) +   
                                  word.substring(1);   
                         });   

}  


Related articles: