Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script

Status
Not open for further replies.

NickC111

Technical User
Sep 23, 2010
44
GB
I have a text file with an email address

Example

From: t.test@hotmail.co.uk 454445454545454

I want to extract the email address into a new text file

Any ideas?
 
Use the FileSystemObject to open, read and create a new file.
Use the left() and instr() functions to extract the data


Code:
set objFSO = CreateObject("Scripting.FileSystemObject")

set objInFile = objFSO.OpenTextFile("C:\filename_in.txt", 1, true, 0)
set objOutFile = objFSO.OpenTextFile("C:\filename_out.txt", 2, true, 0)

do while not (objInFile.AtEndOfStream)
   strLine = objInFile.ReadLine
   strEmail = left(strLine, instr(strLine, " "))
   objOutFile.WriteLine strEmail
loop


objInFile.close
objOutFile.close

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Geates, why not simply use the Split function ?
Code:
If Left(strLine, 6) = "From: " Then
  strEmail = Split(strLine)(1)
...

FYI your suggestion will put "From: " into strEmail

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I didn't notice "From:"

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top