String conversion

I want to do a string conversion for a text box entry. No matter what the user enters I want to convert it to Sentence case. (first letter is capitalized, the rest are lower case). What I did was an On Text Change event to create 2 variables using a slice function. The first variable is created by slicing off the first character and changing it toUpperCase. The second is from slicing off the remainder and changing it toLowerCase. Then I concatenate the two strings into a single text display. (could also create a new variable from the concatenation).

My question is…is there an easier way to do this? It seems sort of klugy. Also how would I handle a string entry with a space in it? (e.g. a last name of “De Silva”)

SentenceCaseDemo.rp (47.1 KB)

There’s no need for variables here. Assuming a variable (global or local) called text with the text in question:

Set text on widget: [[text.substr(0,1).toUpperCase()]][[text.slice(1).toLowerCase()]]

The first set of brackets makes the first letter uppercase and the second set makes the rest lower case. Same as you described but without any variable, all in two expressions in a single action.

1 Like


This file puts each word in the string into sentence case incorporating Nathan’s code above. Most of the code (as well as an explanation of what’s going on) is in the dynamic panel to the right of the field. A little bit of code is in the OnLostFocus event handler of the field itself.

Live sample

File: sentenceCase.rp (146.1 KB)

1 Like

Many thanks for the rp and the documentation you included in it.

Awesome - thank you! I figured there was a way to string functions together but I’ve got a lot of javascript learning to do.