Text Analysis – Get Words Starting With Uppercase
Extracts and returns a list of words from a string that start with an uppercase letter.
The function scans the input character by character and starts a new word every time it encounters an uppercase letter. It accumulates characters until the next uppercase letter is found, at which point it finalizes the previous word.
VB
Public Function GetWordsStartingWithUppercase(ByVal input As String) As List(Of String)
If String.IsNullOrEmpty(input) Then
Return New List(Of String)()
End If
Dim result As New List(Of String)
Dim currentWord As String = String.Empty
' loop on chars
For Each c As Char In input
If Char.IsUpper(c) Then
' New word start
If currentWord <> String.Empty Then
result.Add(currentWord.Trim())
End If
currentWord = c
Else
currentWord &= c
End If
Next
' Add last word if any
If currentWord <> String.Empty Then
result.Add(currentWord.Trim())
End If
Return result
End Function