Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-02-2009, 5:28 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Mar 2009
Age: 22
Posts: 4
Reputation: 0
meloco is on a distinguished programming path ahead
Default compare between 2 txt files and save it in new txt

Hi there,

I have many txt files, and i have to select any txt file to search and compare match fields with file: CompareText.txt. My text file format:


20090227#2#B010110100#3787.562904#
20090227#2#B010110200#430556.987989#
20090227#2#B010110213#2146515.91#
20090227#2#B010110211#14073.69#
......


CompareText.txt

B010110200
B010110400
B010110413
B010110411
B010110213

, I can get the same result
(depend on the third column to compare), then i must save this result to new txt file . Examples, this result from 2 txt files:

20090227#2#B010110200#430556.987989#
20090227#2#B010110213#2146515.91#

Does anyone have code for this?? Thanks in advance
Best Regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-15-2009, 11:50 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2006
Location: UK
Age: 26
Posts: 54
Reputation: 44
LeonR is on a distinguished programming path ahead
Default

Ok, so basically you want to return the whole line from the original text file if it has a match for the string you searched for?

I would do it like this:-

1.) Read the text file into an array of somekind - or step through one line at a time.
2.) loop through each element and see if it contains your search string.
If it does contain the search string, then append that line onto another array

3.) once all lines have been searched against the search strings, write the array you created to a new file.

Thats what springs to mind. I don't know the code off the top of my head so sorry I can't help anymore.

Last edited by LeonR; 04-15-2009 at 4:49 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2009, 12:40 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Mar 2009
Age: 22
Posts: 4
Reputation: 0
meloco is on a distinguished programming path ahead
Default

thanks u, i done
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2009, 5:05 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Quote:
Originally Posted by LeonR View Post
1.) Read the text file into an array of somekind - or step through one line at a time.
2.) loop through each element and see if it contains your search string.
If it does contain the search string, then append that line onto another array
Bad idea; for a 1000 line file you might need up to 1 million comparisons, which is O^2, which is bad (slow)

Use a Dictionary
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-17-2009, 5:22 AM
VB.NET Forum Enthusiast
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Nov 2006
Location: UK
Age: 26
Posts: 54
Reputation: 44
LeonR is on a distinguished programming path ahead
Default

Quote:
Originally Posted by cjard View Post
Bad idea; for a 1000 line file you might need up to 1 million comparisons, which is O^2, which is bad (slow)

Use a Dictionary

I think i'm still stuck in the old times!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 1:31 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.