Finding the first capital letter in a string

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
 
D

Douglas J. Steele

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
 
H

hans.stope

Thanks Doug, That was awesome. It helped me finish my project.

Thanks again,
Hans
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top