By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,220 Members | 1,724 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,220 IT Pros & Developers. It's quick & easy.

Finding the position of the first capital in a string

P: 1
I need to split names in a table field that have prefixes, like: van den Eden.

If I had a function that would find the first capital in a string, and show everything to the left of the first capital, my puzzel would be solved.

From the example: "van den Eden", I would be left with: "van den"

Can anyone help me?
Mar 30 '07 #1
Share this Question
Share on Google+
1 Reply

P: 69
Try this.

Expand|Select|Wrap|Line Numbers
  1. Private Function Text_Left_Of_Cap_Char(Str As String) As String
  2. Dim MyCounter As Long  'Counter to loop through each character of the string
  3. Dim MyCharacter As String  'String to hold each character of the string
  5.     'Loops through each character of the string
  6.     For MyCounter = 1 To Len(Str)
  8.         'Holds a character
  9.         MyCharacter = Mid(Str, MyCounter, 1)
  11.         'The next line converts the character to its corrisponding Ascii value.
  12.         'Ascii values of 65 to 90 represent capitol letters
  13.         If Asc(MyCharacter) >= 65 And Asc(MyCharacter) <= 90 Then
  15.             'Return the all of the characters to the left of capitol character
  16.             Text_Left_Of_Cap_Char = Mid(Str, 1, MyCounter - 1)
  18.             'Since a capitol letter has been found, exit the loop
  19.             MyCounter = Len(Str)
  21.         End If
  22.     Next
  24. End Function
Mar 30 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.