|
-
Oct 16th, 2007, 07:25 AM
#1
Thread Starter
Addicted Member
[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!
-
Oct 16th, 2007, 07:38 AM
#2
Frenzied Member
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
-
Oct 16th, 2007, 07:44 AM
#3
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)
-
Oct 16th, 2007, 07:45 AM
#4
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.
-
Oct 16th, 2007, 09:08 AM
#5
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
-
Oct 17th, 2007, 07:37 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|