Is there a text mask to do this?


Is there a mask for a text field that will capitalise the first letter of every word (where the entry could be any number of words)?

eg “this IS wHat I want” —> “This Is What I Want”

I have a feeling I’ll need to do this programatically in the TextChanged event but thought I’d see if there was some mask genius out there first!

I’m not aware of any method for doing this.
I’d write a String extension method like:

[code]Function Capitalize(Extends s As String)
// do your stuff here on s
// and return the capitalized string
// possibly using RegEx to find every word
// and change its initial letter to uppercase

return MyCapitalizedString

End Function[/code]

Or using text datatype

Private Sub TitleCase(extends inText As Text) Dim words() As Text = inText.Split(" ") For each word as Text in Words word = word.Uppercase.Left(1) + word.mid(1).Lowercase next inText = text.Join(words, " ") End Sub

How about TitleCase? :wink:

1 Like

[quote=183548:@Markus Winter]How about TitleCase? :wink:[/quote]

Now I know why it worked before I wrote the extension :stuck_out_tongue:

[quote=183548:@Markus Winter]How about TitleCase? :wink:[/quote]

Thanks Markus - that looks like The Droid I’m Looking For!

I know this is a fairly old discussion but I have a similar need. However, I’m more concerned about UX.

My reading (and fooling around with) String.Titlecase tells me it’s designed to take an input and convert it on output, regex style. But what if you want certain text fields or combo boxes to present the user with title case by default? ie. converting as they type.

You would have to implement that in the KeyDown event. If it’s the first character or if it has a space in front of it, capitalize. Otherwise, lowercase it.