VBScript to search two Strings in a TXT -


i try make vbscript read txt , search 2 strings , gives out only last results.

string 1: hello123

string 2: test123

the txt looks this:

27.07.2010 09:45 ... dumdumdum ...  27.07.2010 09:45 ... blablabla ...  27.07.2010 09:45 ... hello123 ...  27.07.2010 09:45 ... blablabla ...  27.07.2010 09:45 ... dumdumdum ...  27.07.2010 09:45 ... dumdumdum ...  27.07.2010 09:45 ... hello123 ...   'this result 27.07.2010 09:45 ... blablabla ...  27.07.2010 09:45 ... blablabla ...  27.07.2010 09:45 ... dumdumdum ...  27.07.2010 09:45 ... test123 ...  27.07.2010 09:45 ... dumdumdum ...  27.07.2010 09:45 ... test123 ...        'and result 27.07.2010 09:45 ... dumdumdum ...  27.07.2010 09:45 ... blablabla ...  

i try this, don't know how this:

read txt readall think , search part.

if string 1 not found     msgbox "nothing found"     goto next else     if string 2 not found         msgbox "nothing found"     else         msgbox "found"      end if end if next 

has idea , can me?

greetings, matthias

if not part of bigger vbscript program , have luxury download stuff, can use file processing tool, such gawk windows eg 1 liner

c:\test> gawk "/hallo123/{h=$0}/test123/{t=$0}end{print h \"\n\" t}" file 27.07.2010 09:45 ... hallo123 ...   'this result 27.07.2010 09:45 ... test123 ...        'and result 

with vbscript, use instr() check each string "hallo123" , "test123", if found, assign variable line. @ end of file iteration, print out 2 variables.

example searching "hallo"

set objfs = createobject("scripting.filesystemobject") 'file scan strfile = "c:\test\file.txt" 'pattern search for, eg hallo strpattern = "hallo" set objfile = objfs.opentextfile(strfile) until objfile.atendofstream     strline = objfile.readline       if instr(strline,strpattern)>0         wscript.echo strline                 h=strline     end if   loop wscript.echo h  

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -