UcWords
Public Module StringExtensions ''' <summary> ''' Capitalise the first letter of each word / Tilte Case ''' </summary> ''' <param name="words">A string - paragraph or sentence</param> ''' <returns>String</returns> <Runtime.CompilerServices.Extension()> _ Public Function UcWords(ByVal words As String) Dim output As StringBuilder = New StringBuilder() Dim exploded = words.Split({" "c}) If (exploded IsNot Nothing) Then For Each word As String In exploded output.Append(word.Substring(0, 1).ToUpper) _ .Append(word.Substring(1, word.Length - 1)) _ .Append(" ") Next End If Return output.ToString() End Function End ModuleExample:
Dim sentence As String = "I am a sentence of words" Dim capitalised As String = sentence.UcWords() ' capitalised: "I Am A Sentence Of Words"
Description
Returns Title Cae. Capitalise first letter of each word
Details
- Author: Stuart Sillitoe
- Submitted on: 7/7/2016 12:58:40 PM
- Language: VB
- Type: String
- Views: 1477
Double click on the code to select all.