Functions

Xkape

Newcomer
Joined
Apr 17, 2003
Messages
12
Location
Nashville, TN
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
 
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.
 
Last edited:
This code should do a char by char comparison
Visual Basic:
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:
C#:
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;
	}
}
 
Last edited:
Back
Top