Extract Name

momoko

Registered User.
Local time
Today, 11:53
Joined
Oct 7, 2001
Messages
41
Hi,
How can I do the following :
I've a name field which I would like to extract part of the information. For e.g

Tom Cat Dog, how can I extract just the initate, C from Cat and D from Dog so that my name will appear Tom C D

Thanks,
 
I think this is a FAQ or a Sample... Have you tried searching?

Regards
 
Hi,

Yes have tried searching and trying to find some solution here and there from the various thread that is being posted previously.
 
Without putting too much thought into it one method is to search the the string for spaces using the MID function and then extract the letters after the spaces. Of course this assumes that there will always be spaces before the letters you want,that the first name will always be followed by a space. and that there will be no odd characters numbers etc. If you have a lot of records to process this maybe a rather slow way of solving the problem. If it is just capital letters you are looking for you could try checking that the ascii code for the characters lies within the range of values for capital letters in the ascii character table.
 
Code:
Public Function GetWords(ByVal strText As String) As String
    
    On Error GoTo Err_GetWords
    
    Const vbSpace As String = " "
    
    Dim bytCounter As Byte
    Dim strNames() As String
    
    strNames = Split(strText, vbSpace)
    
    For bytCounter = LBound(strNames()) To UBound(strNames())
        If bytCounter = 0 Then
            GetWords = strNames(bytCounter) & vbSpace
        Else
            GetWords = GetWords & Left$(strNames(bytCounter), 1) & vbSpace
        End If
    Next bytCounter
    
    Exit Function
        
Err_GetWords:
    GetWords = vbNullString
    
End Function
 
Hi,

Thanks! I manage to get it working. Brillant!
 

Users who are viewing this thread

Back
Top Bottom