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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locate text in a file, knowing only the start of the string

Status
Not open for further replies.

MadGeni

Technical User
Dec 13, 2002
19
GB
Hi there,

i've searched around ( honest! ) for an answer to this, however i keep getting stumped.
Essentially i have a file with an email address in. The email address can change, the only constant is that it is preceded by "!email: ". There's no end character after the address ( although there is a vbcrlf )
I can locate the !email part easily, however i can't then think of a neat way of assessing the address itself to trim it.
Help much appreciated!
 
Assuming the line in question looks like this:

!email: JoeBloggs@hotmail.com

then this should do the trick...
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\myfile.txt",1)

Do While NOT objFile.AtEndOfStream AND strEmail = ""
 strText = objFile.ReadLine()

 If InStr(strText, "!email: ") Then
  strEmail = Right(strText, (Len(strText) - 8))
 End If
Loop

objFile.Close

Set objFile = Nothing
Set objFSO = Nothing

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top