What's Here?
- Members: 340,136
- Replies: 920,468
- Topics: 154,937
- Snippets: 4,855
- Tutorials: 1,257
- Total Online: 3,924
- Members: 136
- Guests: 3,788
|
Welcome to Dream.In.Code |
|
|
Become an Expert!
Join 340,136 Programmers for FREE! Get instant access to thousands  of experts, tutorials, code snippets, and more! There are 3,924 people online right now. Registration is fast and FREE... Join Now!
Chat LIVE With a Expert
|
compare between 2 txt files and save it in new txt . P
compare between 2 txt files and save it in new txt . P
Rate Topic:
   

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
09-March 09
Dream Kudos: 0
Posted 02 April 2009 - 12:02 AM
iam newbie to this, hope your help
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#
help Pls urgent...thanks in advance
Best Regards
This post has been edited by meloco: 02 April 2009 - 12:29 AM
Posted 02 April 2009 - 01:01 AM
The following tutorial could of some use to you.
Tutorial: TextFieldParser Tutorial

- apt-get install DIC.bin
-
-
Group:
Admins
-
Posts:
16,211
-
Joined:
26-July 07
Dream Kudos: 12400
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery
Posted 02 April 2009 - 07:10 AM
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well. Please post like this:  Thank you for helping us helping you.

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
09-March 09
Dream Kudos: 0
Posted 06 April 2009 - 07:00 PM
ok, thanks u all,
I find the solution to solve, that is: I will import all content with # delimited into a table called Import in Access and after that i will export this table into a datagridview and then i will export it into other text file, but i get errors when i import txt file into Access. This is my code:
Name of text file: BC0902281.A0131700101 -> i get id from a part of txt name : 01317001.
Content of txt file:
BG#01317001#D01#
20090228#5#D0101#1274193999025#
20090228#5#D0102#1227149540626#
EN#01317001#D01#2#
BG#01317001#A0101#
these lines contain EN and BG must not be inserted into acess
Private Function sqlInsert(ByVal id As String, ByVal name As String, ByVal info As String, ByVal qual As double, ByVal datetime As String) As String
Dim sql As String
sql = ""
sql = sql & "INSERT INTO IMPORT (id, name, info, qual, datetime) VALUES("
sql = sql & "'" & id & "' "
sql = sql & ",'" & name & "' "
sql = sql & ",'" & info & "' "
sql = sql & ",'" & qual & "' "
sql = sql & ",'" & datetime & "' "
sql = sql & ")"
sqlInsert = sql
End Function
Private Sub btnFileName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileName.Click
Dim Conn As New System.Data.OleDb.OleDbConnection
Dim Comm As New System.Data.OleDb.OleDbCommand
Dim i As Integer
Dim arrLine As String()
Dim arrLines As String()
Dim strFileName As String
Dim sql As String
Dim rsl As DialogResult
Conn.ConnectionString = getConnectionString_MSACCESS("\\server\Data\test\SELECT_FILES\db1.mdb", "", "")
Conn.Open()
Comm.Connection = Conn
With Me.OpenFileDialog1
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.Multiselect = True
.Title = "Text files Browser"
rsl = .ShowDialog()
If rsl = Windows.Forms.DialogResult.OK Then
For Each s As String In OpenFileDialog1.FileNames
Dim fi = OpenFileDialog1.FileName
strFileName = IO.Path.GetFileName(s)
txtText.Text = fi
MessageBox.Show(strFileName)
arrLines = System.IO.File.ReadAllLines(strFileName)
Dim id, name, info, qual, datetime As String
id = ""
datetime = ""
If arrLines.Length > 0 Then
datetime = arrLines(0).ToString()
arrLine = arrLines(0).ToString().Split("#")
datetime = arrLine(1).Substring(4, arrLine(1).Length - 4)+ "/" + arrLine(1).Substring(2, 2) + "/" + arrLine(1).Substring(0, 2)
id = strFileName.Substring(strFileName.Length - 14, 8)
End If
For i = 1 To arrLines.Length - 1
arrLine = arrLines(i).ToString().Split("#")
If arrLine(0) <> "EN" And arrLine.Length = 4 Then
name = arrLine(0)
info = arrLine(1)
qual = arrLine(2)
sql = sqlInsert(id, name, info, qual, datetime ) Comm.Connection = Conn
Comm.CommandText = sql
Comm.ExecuteNonQuery()
End If
Next
Next
MessageBox.Show("Sucessfully!")
End If
End With
End Sub
plz help me. thanks
This post has been edited by meloco: 06 April 2009 - 07:03 PM

- apt-get install DIC.bin
-
-
Group:
Admins
-
Posts:
16,211
-
Joined:
26-July 07
Dream Kudos: 12400
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery
Posted 06 April 2009 - 08:31 PM
A note, in VB.NET you no longer need to add to a string like str = str & "SomeValue, you can use the C++ syntax like str &= "SomeValue" (makes less typing for you)
Private Function sqlInsert(ByVal id As String, ByVal name As String, ByVal info As String, ByVal qual As double, ByVal datetime As String) As String
Dim sql As String
sql = ""
sql &= "INSERT INTO IMPORT (id, name, info, qual, datetime) VALUES("
sql &= "'" & id & "' "
sql &= ",'" & name & "' "
sql &= ",'" & info & "' "
sql &= ",'" & qual & "' "
sql &= ",'" & datetime & "' "
sql &= ")"
Return sql
End Function

- New D.I.C Head
-
-
Group:
New Members
-
Posts:
4
-
Joined:
09-March 09
Dream Kudos: 0
Posted 06 April 2009 - 10:47 PM
but my problem is my txt contains many "BG" and "EN" lines, its content:
BG#01505001#B0101#
20090327#2#B010110100#0#
20090327#2#B010110200#171391.384433#
20090327#2#B010110213#1046589.24#
20090327#2#B010110211#6973.69#
20090327#2#B01012011111#1581.58#
EN#01505001#B0101#43#
BG#01505001#A07#
20090227#2#A07910100#507135679694#
20090227#2#A07910113#8863883.56#
.....
I must remove BG and EN line and there are 2 datetime fields in the above examples: 20090327 -> 27/03/2009; 20090227 ->27/02/2009; name field is insert in access is: 2; info: is the third array...
1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|