Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > grep function?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-09-2003, 02:02 PM
Mat_J Mat_J is offline
Newcomer
 
Join Date: Jun 2003
Posts: 8
Default grep function?


I'm wondering if there is a function that is in any way equivalent to the grep function that is found on unix machines within visual basic. I would like to search through a number of text files for a certain string of characters, and grep seems like the option I would choose?

Does VB have this, or am I going to have to devise some complicated file I/O function?


Mat
Reply With Quote
  #2  
Old 06-09-2003, 02:21 PM
excaliber's Avatar
excaliber excaliber is offline
Senior Contributor

* Expert *
 
Join Date: Nov 2002
Location: Ohio, USA
Posts: 1,828
Default

Well, not complicated. You will have to open the file:

Code:
Open app.path & "\bob.txt" for binary as #1 'Open the file for bianry access get #1,1,strHolder 'get, starting at byte one, and place in strHolder close #1 'close the file

Once its been placed in strHolder, you can use the InStr fucntion to search the string:

Code:
temp = instr(1,strHolder,"Bob") 'search the string for first occurance of "Bob"

This will return the character number of the strin "Bob" inside of strHolder. It will return 0 if not found.

Or you can use InStrRev(). The search begins from the end of string, but the position returned counts from the beginning of the string
__________________
RandomIRC - Your neighborhood's friendly IRC channel (irc.randomirc.com - #code)

"Perl - The only language that looks the same before and after RSA encryption."
Reply With Quote
  #3  
Old 06-09-2003, 02:51 PM
waits77 waits77 is offline
Senior Contributor
 
Join Date: May 2003
Posts: 805
Default

If you're familiar with regular expressions, VB6 has a lot of functionality. You would still have to open the file and read the contents into a string, but then you could search for patterns specified just as you would with egrep (extended grep). Take a look at:
http://www.15seconds.com/issue/010301.htm
http://msdn.microsoft.com/library/de...ting051099.asp

Quote:
Originally Posted by Mat_J
I'm wondering if there is a function that is in any way equivalent to the grep function that is found on unix machines within visual basic. I would like to search through a number of text files for a certain string of characters, and grep seems like the option I would choose?

Does VB have this, or am I going to have to devise some complicated file I/O function?


Mat

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help! i'm a beginner geekool General 7 04-26-2003 12:44 AM
Detecting When Menu Is Clicked In External Application skript_kiddie General 1 08-04-2002 05:53 AM
Shareware Registry Protection Technigue karachi999 General 2 01-21-2002 02:40 PM
MS Winsocket gibson General 3 07-20-2001 10:03 AM
link function to textboxes golash General 2 05-03-2001 11:57 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->