by mike ruberto (2 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 23rd August 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)
' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing the first letter. It also capitalizes the
' www.indridcold.conk.com
' the following sub is designed to clean up strings by removing leading-
' spaces and capitalizing the first letter. It also capitalizes the first letter-
' found after any embedded spaces and removes trailing spaces.
' this code is used for making sure a persons name prints out nicely regardless
' of how it was typed in. great for programs that handle guest/cust. info.
' e.g. name as typed: mike a ruberto - name after process:Mike A Ruberto-
Public Sub firstLetterCaps(anyString As String)
Dim numofletters As Integer
Dim MyPos1 As Integer
Dim MyPos2 As Integer
Dim tempstr1 As String
Dim SearchChar As String
Dim index As Long
SearchChar = " " ' search character is a blank space
anyString = LTrim(anyString)
numofletters = Len(anyString)
MyPos1 = InStr(1, anyString, SearchChar, 1)
MyPos1 = MyPos1 + 1
index = 1
Do While index <= numofletters
Rem picking the string apart letter by letter and capitalizing first letter
SearchChar = Mid(anyString, index, 1)
If index = 1 Then
SearchChar = UCase(SearchChar)
ElseIf index = MyPos1 Then
SearchChar = UCase(SearchChar)
End If
Rem now searching for embedded spaces and letters to make caps
If SearchChar = " " And index > MyPos1 Then
MyPos2 = InStr(MyPos1, anyString, " ", 1)
End If
If index = MyPos2 + 1 Then
SearchChar = UCase(SearchChar)
End If
tempstr1 = tempstr1 & SearchChar
index = index + 1
Loop
tempstr1 = RTrim(tempstr1)
anyString = tempstr1 ' assigning result here, happy now?
End Sub
No comments have been posted about ' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing . Why not be the first to post a comment about ' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing .