Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2005, 09:53 AM
Registered User
 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to broadbandguru
Default Search for unknown charictors in a txt file

I have been trying to figure this out for some time now and I'm getting frusturated, I'm hoping you vetrians can help me...I want to be able to extract addresses and names from a textfile. The catch is that the addressess and names change and I the only thing that doesn't change is the charitors before and after it. I was woundering if there is some way I can code it to say " copy all charitors when reaching 'a specified string' until 'second specified string'" For instance: <b><b xmlns=""> Name here </b>. How do I tell the code to search the text file and extract the 'name here' string?

Anything worth doing is worth doing good
 
Old September 16th, 2005, 09:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Well, you can read the entire string and use a combination of the MID and REPLACE functions to get rid of characters such as < > " = but the problem is you also have <b> in there and the letter "b" is a valid character. Your addresses may have that letter in them as well. You'd also have to code to check for the combination strings "<b>" and "</b>".


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old September 16th, 2005, 01:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you can read the whole file into a string, you can use this method to look for all the strings included between two tokens. This method just prints them out, you have to decide what to do with them. This is a snippet of the code I use.
Marco

Private Sub FindTokens(s As String, sStart As String, sEnd As String)

    Dim k1 As Long
    Dim k2 As Long
    Dim kin As Long
    kin = 1

    Do
        k1 = InStr(kin, s, sStart, vbTextCompare)
        If k1 <= 0 Then Exit Sub
        k1 = k1 + Len(sStart)
        k2 = InStr(k1, s, sEnd, vbTextCompare)
        If k2 <= 0 Then Exit Sub

        Debug.Print Mid$(s, k1, k2 - k1) '' or put them in an array or something

        kin = k2 + Len(sStart)
    Loop

End Sub
 
Old September 16th, 2005, 05:46 PM
Registered User
 
Join Date: Sep 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to broadbandguru
Default

I appreciate both of your help, I will try your suggestions and hopefully they work. Thank you

Anything worth doing is worth doing good





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in File UNKNOWN.RPT babarrana Crystal Reports 0 September 17th, 2007 05:47 AM
exporting pdf search plugin results to .txt file solos Pro Visual Basic 2005 0 August 6th, 2007 12:01 PM
Unknown File Format - how to solve thomaz C# 1 February 12th, 2004 10:41 AM
Getting a search txt box to work JJ Access VBA 4 October 23rd, 2003 10:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.