JavaScript

StringtoCase Method

Syntax

String.toCase(case)

Arguments

casestring

The case to return the string in.

Returns

valuestring

The value of the string in the passed in case.

Description

Extension to the native string variable to convert a string into a given case.

Discussion

The String.toCase method will convert a string into a number of optional cases. These are:

"upper" or "u" to convert to upper-case.

"lower" or "l" to convert to lower-case.

"sentence" or "s" to convert to sentence-case (the first letter of the first word in a sentence is upper-case the rest are lower).

"title", "t" to convert to title-case (the first letter of each word is upper-case).

Example

var str = 'hello world';
str = str.toCase('t');
// str = 'Hello World'