- Home
·
- String Manipulation
·
- ' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing
' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing
' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing the first letter. It also capitalizes the
Rate ' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing
(2(2 Vote))
' 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
' the following sub is designed to clean up strings by removing leading- ' spaces and capitalizing Comments
No comments yet — be the first to post one!
Post a Comment