UCFirst

Transform the first letter of a string to uppercase or the first letter of each word, and optionally lowercase uppercase characters.

Method Signature

UCFirst(string=[string], doAll=[boolean], doLowerIfAllUppercase=[boolean])

Arguments

Argument
Type
Required
Description
Default

string

string

true

The string to transform.

doAll

boolean

false

Boolean flag indicating whether to transform the first letter of each word.

false

doLowerIfAllUppercase

boolean

false

Boolean flag indicating whether to lowercase uppercase characters.

false

Examples

Basic usage

Capitalizes the first character of the first word only.

Run Example

ucFirst( "hello world!" );

Result: Hello world!

Capitalize all the words in string

Using the optional doAll parameter capitalizes the first character of all words. Word separators are: whitespace, period, parenthesis, or dash.

ucFirst( "boxlang.ortusbooks.com is your (everyone's) resource for BX-related documentation!", true );

Result: boxlang.ortusbooks.com Is Your (everyone's) Resource For BX-related Documentation!

Handling of strings in all uppercase

Using the optional doLowerIfAllUppercase parameter allows for intelligent capitalization of words in all caps.

ucFirst( "boxlang.ortusbooks.com YOUR (EVERYONE'S) RESOURCE FOR BX-related DOCUMENTATION!", true, true );

Result: boxlang.ortusbooks.com Your (everyone's) Resource For BX-related Documentation!

Additional Examples

string = "submitting bugs and feature requests via our online system";
dump( UcFirst( string, false, false ) );
dump( UcFirst( string, true, false ) );

Last updated

Was this helpful?