capitalize: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
(Adding optional second parameter coming in 1.8. Removed "proposed" flag.)
Line 1: Line 1:
{{MacroFunction
{{MacroFunction
|name=capitalize
|name=capitalize
|proposed=true
|proposed=false
|trusted=false
|trusted=false
|version=1.5.7
|version=1.5.7
|description=
|description=
Returns the passed string back with the first letter of each word capitalized. This means that "bump player health" becomes "Bump Player Health". Numbers and symbols in the strings are treated as word boundaries.
Returns the passed string back with the first letter of each word capitalized. This means that "bump player health" becomes "Bump Player Health". By default, numbers and symbols in the strings are treated as word boundaries.


|usage=
|usage=
<source lang="mtmacro" line>
<source lang="mtmacro" line>
capitalize(input)
capitalize(input)
</source>
==== Options coming in 1.8 ====
<source lang="mtmacro" line>
capitalize(input, treatNumbersSymbolsAsBoundaries)
</source>
</source>
'''Parameters'''
'''Parameters'''
{{param|input|String to be converted.}}
{{param|input|String to be converted.}}
 
{{param|treatNumbersSymbolsAsBoundaries|'''Coming in 1.8'''. Whether numbers and symbols should be treated as word boundaries - defaults to {{code|true}}({{code|1}}).}}
|example=
|example=
Converting character name.
Converting character name.
Line 34: Line 38:
A 4Ever 2Una
A 4Ever 2Una
</source>
</source>
 
==== Changes Coming in 1.8 ====
String with numbers and symbols:
<source lang="mtmacro" line>
[h: vLine = "he's sure i'll see you 1st, o'shea"]
[r: capitalize(vLine)]
[r: capitalize(vLine, 0)]
</source>
Returns:
<source lang="mtmacro">
He'S Sure I'Ll See You 1St, O'Shea
He's Sure I'll See You 1st, O'shea
</source>
|also=
|also=
{{func|upper}} {{func|lower}}
{{func|upper}} {{func|lower}}
Line 40: Line 55:
|changes=
|changes=
* '''1.5.7''' - Added function.
* '''1.5.7''' - Added function.
* '''1.8''' - Added optional param to control treatment of numbers and symbols as word boundaries.
}}
}}
[[Category:String Function]]
[[Category:String Function]]

Revision as of 20:20, 20 June 2020

capitalize() Function

Introduced in version 1.5.7
Returns the passed string back with the first letter of each word capitalized. This means that "bump player health" becomes "Bump Player Health". By default, numbers and symbols in the strings are treated as word boundaries.

Usage

capitalize(input)

Options coming in 1.8

capitalize(input, treatNumbersSymbolsAsBoundaries)

Parameters

  • input - String to be converted.
  • treatNumbersSymbolsAsBoundaries - Coming in 1.8. Whether numbers and symbols should be treated as word boundaries - defaults to true(1).

Example

Converting character name.
[r: name = getTokenName()]<br>
[r: capitalize(name)]

Returns:

ichabod crane
Ichabod Crane

String with numbers and symbols.

[r: capitalize("a 4ever 2/una")]

Returns:

A 4Ever 2Una

Changes Coming in 1.8

String with numbers and symbols:

[h: vLine = "he's sure i'll see you 1st, o'shea"]
[r: capitalize(vLine)]
[r: capitalize(vLine, 0)]

Returns:

He'S Sure I'Ll See You 1St, O'Shea
He's Sure I'll See You 1st, O'shea

See Also

Version Changes

  • 1.5.7 - Added function.
  • 1.8 - Added optional param to control treatment of numbers and symbols as word boundaries.