Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


using the preceding character in a search string.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60232
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> using the preceding character in a search string.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 using the preceding character in a search string. - 5/15/2008 12:00:57 AM   
  garfunkal

 

Posts: 25
Score: 0
Joined: 3/5/2008
Status: offline
i am writing the code below - the aim of which is to find a specified phrase within a string - and as part of a bigger piece of code keep a running count of occurances within a file.

the problem I am having is that multiple occurances in a line are defined by a digit before the phrase - for example 4FTF (from the pattern) would need to be counted 4 times.  The code i have bludgoned together takes the occurance of the pattern in the string, and then takes the preceding character out - the plan being to use that number to add to the running total.  The problem in that if i use MID it doesnt return the number if there is one... I am not even sure if this is the best way to use the data.  Any ideas/suggestions?

below is the code, and below that a snippet of the data used - note how the character before the searched for phrase is not always a number!



code......

Set fso = CreateObject("Scripting.FileSystemObject")
set logfile = fso.OpenTextFile("U:\Lotus VBScript\log2.txt", 1, True)
     
Do until logfile.AtEndOfStream
Set RegEx = New RegExp
RegEx.Pattern = "F2F|FTF|Face To Face|Facetoface|QC|Quality Control"
RegEx.IgnoreCase = True
RegEx.Global = True
nextline = logfile.ReadLine
Set expressionmatch = RegEx.Execute(nextline)
If expressionmatch.Count > 0 Then
 For Each expressionmatched in expressionmatch
  foundat = (expressionmatched.FirstIndex)-1
  MyString = (Mid(nextline,foundat,1))
  msgbox mystring
 Next
end if
loop

data....

Nigel Ford -=- BIRMINGHAM -=- 08/05/2008 00:00
Nigel Ford -=- BIRMINGHAM -=- 09/05/2008 00:00
Nigel Ford -=- presentation - Risk Solutions loaction: room 4C & 4D Birmingham -=- 09/05/2008 12:00
Nigel Ford -=- 6F2F: Towergate tlc location Birmingham RSA -=- 12/05/2008 09:30
Nigel Ford -=- F2F: CJN Insurance -=- 12/05/2008 11:30
Nigel Ford -=- Elizabeth Arobaga-Edafe meeting location Birmingham -=- 12/05/2008 13:30
Nigel Ford -=- Day Off - meeting -=- 12/05/2008 15:30
Nigel Ford -=- Holidays -=- 13/05/2008 00:00
Nigel Ford -=- 4F2F: Corrigans - trading team visit location: Birmingham -=- 13/05/2008 11:00
Nigel Ford -=- 5F2F: Honour Point location: Edgbaston -=- 13/05/2008 14:30
Nigel Ford -=- BIRMINGHAM -=- 14/05/2008 00:00
 
 
Post #: 1
 
 RE: using the preceding character in a search string. - 5/15/2008 12:19:24 AM   
  ebgreen


Posts: 5041
Score: 31
Joined: 7/12/2005
Status: offline
See if this gets you going in the right direction:

Set fso = CreateObject("Scripting.FileSystemObject")
set logfile = fso.OpenTextFile("C:\Temp\foo.txt", 1, True)
    
Do until logfile.AtEndOfStream
Set RegEx = New RegExp
RegEx.Pattern = "(\d*)(F2F|FTF|Face To Face|Facetoface|QC|Quality Control)"
RegEx.IgnoreCase = True
RegEx.Global = True
nextline = logfile.ReadLine
Set expressionmatch = RegEx.Execute(nextline)
If expressionmatch.Count > 0 Then
For Each expressionmatched in expressionmatch
If expressionmatched.Submatches(0) <> "" Then
   WScript.Echo expressionmatched.Submatches(0) & " - " & expressionmatched.Submatches(1)
Else
   WScript.Echo "1 - " & expressionmatched.Value
End If
'foundat = (expressionmatched.FirstIndex)-1
'MyString = (Mid(nextline,foundat,1))
'msgbox mystring
Next
End

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to garfunkal)
 
 
Post #: 2
 
 RE: using the preceding character in a search string. - 5/15/2008 1:11:45 AM   
  garfunkal

 

Posts: 25
Score: 0
Joined: 3/5/2008
Status: offline
excellent - i didnt know submatches where an option - that coupled with the /d* bit is excellent!

thanks so much.

Andrew

(in reply to ebgreen)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> using the preceding character in a search string. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts