Results 1 to 6 of 6

Thread: [RESOLVED] String Function Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Resolved [RESOLVED] String Function Help

    Hi All,

    I have a string that I need to extract only a certain part of the data from:

    SMTP:[email protected]

    I need to extrapolate "Mike.Smith" from the above string.

    I have about 1,000 strings like this, the FirstName.LastName will change on each sting.

    How do I parse out the "SMTP:" and the "@abc.com"?

    Thank you all for your help!

  2. #2
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: String Function Help

    There will be a much cleaner way of doing this but:

    Code:
    Private Sub Command1_Click()
    Dim str As String
    Dim pos As Integer
    
    str = "SMTP:[email protected]"
    pos = InStr(1, str, ":")
    str = Right(str, Len(str) - pos)
    pos = InStr(1, str, "@")
    str = Left(str, pos - 1)
    Debug.Print str
    End Sub

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: String Function Help

    Another possibility
    Code:
    Dim sString As String
    Dim arrName() As String
    Dim arrSplit() As String
    sString = "SMTP:[email protected]"
    arrSplit = Split(sString, "@")
    arrName = Split(arrSplit(0), ":")
    MsgBox arrName(1)

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: String Function Help

    Slightly modified version of 03myersd post and would be very fast since it does not create any intermediary strings... You mentioned you have 1000+ of these to parse...
    Code:
    Dim str As String
    Dim pos As Integer
    str = "SMTP:[email protected]"
    pos = InStr(1, str, ":")
    str = Mid$(str, pos + 1, InStr(pos, str, "@") - pos - 1)
    Edited: removed one unnecessary calculation
    Last edited by LaVolpe; Oct 16th, 2007 at 07:52 AM.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: String Function Help

    And one more possibility:

    Code:
    Dim str As String
    str = "SMTP:[email protected]"
    str = Replace$(str, "SMTP:", "")
    str = Replace$(str, "@abc.com", "")
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: String Function Help

    Very cool. Thank you all for your help.

    I tried all the suggestions given, and everyone worked great. Much appreciated!

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