Results 1 to 6 of 6

Thread: Find an email address in a string

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Find an email address in a string

    I've go a string holding a company name, address, email address, phone and fax number.

    e.g. string="Quadrant Subscription Services Rockwood House Perrymount Road Haywards Heath E-mail: [email protected] Telephone: +44 (0) 1444 445517 Fax: +44 (0) 1444 445526"


    How can I find the email address and put a <B> tag in front of it and a </B> tag at the end?

    like this: <B>[email protected]</B>

    Thanks

    Kati

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Find an email address in a string

    Try:
    VB Code:
    1. Dim s As String
    2.     Dim iEmail As Integer
    3.     Dim iEndEmail As Integer
    4.    
    5.     s = "Quadrant Subscription Services Rockwood House Perrymount Road Haywards Heath E-mail: " & _
    6.       "[email protected] Telephone: +44 (0) 1444 445517 Fax: +44 (0) 1444 445526"
    7.     iEmail = InStr(1, s, "E-mail:", vbTextCompare)
    8.     If iEmail Then
    9.         iEndEmail = InStr(iEmail + 8, s, " ")
    10.         If iEndEmail > iEmail Then
    11.             s = Left$(s, iEmail + 7) & "<B>" & Mid$(s, iEmail + 8, iEndEmail - iEmail - 8) & _
    12.             "</B>" & Mid$(s, iEndEmail)
    13.         End If
    14.     End If
    15.    
    16.     Debug.Print s
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Re: Find an email address in a string

    Thanks for you reply.
    The problem is that I can't rely on the string containing "E-mail:", so I will have to find the "@" symbol somehow and then find the beginning and the end of that string.

    Any ideas?

    Thanks

    Kati

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Find an email address in a string

    Quote Originally Posted by katib
    Thanks for you reply.
    The problem is that I can't rely on the string containing "E-mail:", so I will have to find the "@" symbol somehow and then find the beginning and the end of that string.

    Any ideas?

    Thanks

    Kati
    Try...
    VB Code:
    1. Dim s As String
    2.     Dim iAt As Integer
    3.     Dim iEndEmail As Integer
    4.     Dim iStartEmail As Integer
    5.    
    6.     s = "Quadrant Subscription Services Rockwood House Perrymount Road Haywards Heath E-mail: " & _
    7.       "[email protected] Telephone: +44 (0) 1444 445517 Fax: +44 (0) 1444 445526"
    8.      
    9.     iAt = InStr(1, s, "@")
    10.     If iAt Then
    11.         iStartEmail = InStrRev(Left$(s, iAt), " ")
    12.         If iStartEmail Then
    13.             iEndEmail = InStr(iAt, s, " ")
    14.            
    15.             If iEndEmail > iStartEmail Then
    16.                 s = Left$(s, iStartEmail) & "<B>" & Mid$(s, iStartEmail + 1, _
    17.                   iEndEmail - iStartEmail - 1) & "</B>" & Mid$(s, iEndEmail)
    18.             End If
    19.         End If
    20.     End If
    21.    
    22.     Debug.Print s
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    107

    Re: Find an email address in a string

    Thanks a lot! That worked well.

    Kati

  6. #6
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Find an email address in a string

    Quote Originally Posted by katib
    Thanks a lot! That worked well.

    Kati
    You might want to add "[Resolved]" in the post's subject and/or rate the post.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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