Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Help,Comparing files(Arraylists) in C#


  • Please log in to reply

#1
rahulsinghh

rahulsinghh

    New Member

  • Member
  • Pip
  • 1 posts
Hi guys, I know this kind of query has been answered for java before in this forum, but need some help as i'm doing it in C# .
Well, basically i am required to open files and compare them, n try to find any sort of similar words that occur in both files.
I'm able to open and store the files as arraylists. Then, basically, i've written my own method which removes all tabs, newlines, etc.. and stores these results into a new arraylist, i.e: this being the arraylists i work with( without any extra white spaces, etc...)

When, i try to compare files using a for loop it just compares the last character of my files(arraylist). and returns the result.

Can't figure out why is it not doing for each and every character.
Also, this is the same problem when i try to display the contents of my file(arraylist) in a textbox, it just displays the last character, but not each and every item.

Below, is my method i used to compare the two files.
Plzzzzzz, help me out, n tell me what to do next or do i need to try something totally different.

Your, help wud be most appreciated.
Thanks..

Code:
// The button i click to compare.
private void compare_Click(object sender, System.EventArgs e)
{
// detect1 being my first arraylist
foreach(string compare in detect1)
{

//detect2 being my second file(arraylist).
if(detect2.Contains(compare))
{
int index=detect1.IndexOf(compare);
int index1=index+1;
resultlabel.Text="\nThe word "+compare+" of the first file, is at position "+index1+
" from start, in the second file.";
}
else
{
resultlabel.Text="Sorry, no matches found !!!";
}
}
}



Thanks guys ...

Edited by rahulsinghh, 11 March 2006 - 10:38 AM.

  • 0

Advertisements


#2
darth_ash

darth_ash

    Member 1K

  • Member
  • PipPipPipPip
  • 1,382 posts
Hi,
Don't mind me asking but, why use an ArrayList? You could just put the full two files in seprate string variables and the use the System.String.Compare method.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP