Products | Versions |
---|---|
Spotfire Analyst | All Versions |
There is no built in function for 'title case' like there is with Upper() and Lower(), but it is still possible to perform this string conversion using Spotfire Expressions. Title case, also known as "headline style" and "capital case", is when all words are capitalized, except for certain subsets defined by rules that are not universally standardized. The standardization is only at the level of house styles and individual style manuals. A simplified variant is start case where all words, including articles, prepositions and conjunctions, start with a capital letter.
For example:
or
RXReplace([myString],"(^[a-z]| [a-z])","\\U$1","g")
Explanation:
RXReplace( RXReplace([myString],"(^[a-z]| [a-z])","\\U$1","g"), "(?!^)(A|An|The|This|And|But|Or|For|Nor|At|On|In|For|Since) ","\\L$1 ","g")
Note: the list of words to NOT be capitalized is located in the 3rd line of the above expression and can be edited as required.
Explanation:
Optional:
If the string to be converted is all capitals, then the above expressions will not work since they look for lower case letters to capitalize. In this case, you can use the Lower() function to convert those to lower case first and then the title case conversion will continue as expected:
RXReplace(Lower([myString]),"(^[a-z]| [a-z])","\\U$1","g")or
RXReplace( RXReplace(Lower([myString]),"(^[a-z]| [a-z])","\\U$1","g"), "(?!^)(A|An|The|This|And|But|Or|For|Nor|At|On|In|For|Since) ","\\L$1 ","g")