Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello all,

 

My example first...

 

13DU3T6=Tom in one folder and

 

its equal is in another folder that looks like this below

 

13DU3T6=.txt

 

What Function or statement would you use to have them compared and then populate a textbox with

 

Tom.txt

 

Any advise would be helpful, and thank in advance.

 

J

Posted (edited)
Do you want a character by character or line by line comparison? Edited by AndreRyan
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted (edited)

Do you want C# or VB? And char by char is an exact comparison which is probably what you want.

 

What are you trying to do, exactly? Is it just a bool comparison? In other words, are you just determining if file1 is equal to file2 or not? Or do you want to extract all the sentences or lines that are different into the text box?

 

I also suggest putting your language in your signature so that people know what syntax you want.

Edited by aewarnick
C#
Posted (edited)

This code should do a char by char comparison

Option Explicit On
Option Strict On

Public Class FileCompare
   'Do a character by character comparison for file 1
   Public Shared Function CompareCharByChar(ByVal File1 As String, ByVal File2 As String) As String
       Dim File1Stream As IO.StreamReader = New IO.StreamReader(File1)
       Dim File2Stream As IO.StreamReader = New IO.StreamReader(File2)
       Dim File1Data() As Char = File1Stream.ReadToEnd.ToCharArray
       Dim File2Data() As Char = File2Stream.ReadToEnd.ToCharArray
       File1Stream.Close() : File2Stream.Close()

       Dim Length As Int32, Result As String
       For Length = 1 To File1Data.GetUpperBound(0)
           If File1Data(Length).Equals(File2Data(Length)) Then
               Result &= File1Data(Length).ToString
           End If
       Next

       Return Result
   End Function
End Class

 

And I went to great pain to:

public class FileCompare
{
//Do a character by character comparison for file 1
public string CompareCharByChar(string File1,string File2 )
{
	io.streamreader File1Stream = new io.StreamReader(File1);
	io.streamreader File2Stream = new IO.StreamReader(File2);
	char[] File1Data = File1Stream.ReadToEnd.ToCharArray;
	char[] File2Data = File2Stream.ReadToEnd.ToCharArray;
	File1Stream.Close();
	File2Stream.Close();

	Int32 Length;
	string Result;
	for (Length = 0; Length <= File1Data.GetUpperBound(0); Length++)
		If(File1Data(Length).Equals(File2Data(Length))=True);
			Result &= File1Data(Length).ToString;

	Return Result;
}
}

Edited by AndreRyan
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...