Results 1 to 2 of 2

Thread: Getting first part of a string!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66

    Post

    I want to be able to get someone's first name from a string of text that contains their whole name. The problem is, the whole name has no space in it but the names have capital letters Eg:

    SimonPearce
    JoeBloggs
    FredSmith

    Can anyone work out how I can get a string that just says: Simon, Joe or Fred??

    Thanks!

    Simon

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Try this;

    Function FirstName(FullName As String) As String
    Dim nCount As Integer
    FirstName = ""
    nCount = 1
    While Left(FullName, nCount) = StrConv(Left(FullName, nCount), vbProperCase) And nCount <= Len(FullName)
    FirstName = Left(FullName, nCount)
    nCount = nCount + 1
    Wend
    End Function


    Use it like this

    [firstname]=FirstName("[fullname]")

    eg;

    Msgbox FirstName("MarkBeeton") would display a msgbox with "Mark" on it.

    The code isn't wonderful but it should solve the problem.



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width