Finding the first capital letter in a string

  • Thread starter Thread starter Hans
  • Start date Start date
H

Hans

Does anyone have some code I can use to find the first capital letter in a
string?

I need to split off and show all characters to the left of the Capital
letter.

Thanks
Hans
 
Try something like the following untested air-code:

Function FirstCapital(InputString As String) As Long
' returns 0 if no capital found
Dim lngFirstCapital As Long
Dim lngLoop As Long
Dim strCurrChar As String

lngFirstCapital = 0
For lngLoop = 1 To Len(InputString)
strCurrChar = Mid$(InputString, lngLoop, 1)
If Asc(strCurrChar) >= 65 And _
Asc(strCurrChar) <= 90 Then
lngFirstCapital = lngLoop
Exit For
End If
Next lngLoop

FirstCapital = lngFirstCapital

End Function
 
Back
Top