Array question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chickenman
    New Member
    • Jul 2008
    • 4

    Array question

    Okay I am hoping you all can point me in the correct direction. I am new to the whole C#, .NET stuff but here we go. I have an app that gets a listing of files, and then uses a streamreader to find a specific line in the file and adds this along with the UNC to the filename to an arraylist.

    My problem is this:

    I get it to display the information in the format of:

    fieldA-fieldB,\\server share\filename

    The problem I am trying to resolve is that there can be duplicates in this list for FieldA and B. I need to find all the files that have the same fieldA and B in the list and display them. The differing filenames is what is holding me up I believe.

    Has anyone run across anything that might help me out? Google is your friend, but you have to know what to google first ;)

    Any help would be GREATLY appreciated!
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Well, if I understand your question correctly, you have strings in this format:
    fieldA-fieldB,\\server share\filename
    and you need to find all that have a common fieldA-fieldB?

    Well, if fieldA and fieldB don't have commas in them, you could split the string around a comma, and then compare the first part of the results.

    Code:
    char[] delims = { ',' };
    string[] tokens = stringToSplit.Split(delims);
    //now tokens[0] should have fieldA-fieldB
    So you could add tokens[0] to an array or list and then work your logic to find dups.

    Comment

    • Chickenman
      New Member
      • Jul 2008
      • 4

      #3
      Originally posted by insertAlias
      Well, if I understand your question correctly, you have strings in this format:
      fieldA-fieldB,\\server share\filename
      and you need to find all that have a common fieldA-fieldB?

      Well, if fieldA and fieldB don't have commas in them, you could split the string around a comma, and then compare the first part of the results.

      Code:
      char[] delims = { ',' };
      string[] tokens = stringToSplit.Split(delims);
      //now tokens[0] should have fieldA-fieldB
      So you could add tokens[0] to an array or list and then work your logic to find dups.
      Yes I am doing something like this:
      Code:
      string[] llarray = line.Split(',');
                                  string labelInfo = llarray[1].ToString() + "-" + llarray[2].ToString();
      What is happening is that file A will come along and will look in the empty arraylist and realize it is not in there and add it(which it should do). File B will then come along and see file A and see that it is a duplicate and throw it into Arraylist2.
      That part of the logic is working, but where I run into problems is that they want to know which file that FileB is conflicting with.

      I think the solution is close, I am obviously just not grasping what I need to do to get the corresponding file in Arraylist1 that is causing the duplicates.

      I am sure this is very confusing as I am most likely not saying stuff correctly.

      Thanks!

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        I see. You want to track what filenames that have duplicate fields.

        Well, if I were in your shoes, I'd make my own class. Really simple, just three public strings: fieldA, fieldB, and filename. Then, when I parse my string, I'd create a new instance of this class. Then do your comparisons using the class, and add it to the dup/non-dup lists, and you will have all the information tied together.

        Hope that helps.

        Comment

        Working...