3 Replies - 1449 Views - Last Post: 10 November 2012 - 08:20 AM Rate Topic: -----

#1 cbeier8629  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-November 12

nested loop array search for repeated words

Posted 09 November 2012 - 04:43 PM

Trying to display the repeated names in the text file, in a list box
confused on the loop and nested loop i need to use.. help!!! Thanks

Public Class frmDuplicateNames

    Private Sub btnDetermine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetermine.Click


        Dim array() As String = IO.File.ReadAllLines("Names2.txt")
        Dim intCount = 0
        Dim nameCheck As String



        For Each line In array
            For intCount = 1 To 45 Step 1
                nameCheck = array(intCount)
                


            Next

This post has been edited by Atli: 09 November 2012 - 05:00 PM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: nested loop array search for repeated words

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,090
  • Joined: 02-July 08

Re: nested loop array search for repeated words

Posted 09 November 2012 - 10:24 PM

How about a Dictionary(Of String, Integer)? Once you make an array of words you loop that and if Not ContainsKey(word) then add the new word as the key and the value = 1 else add 1 to that key's value. Then you can LINQ out a list of all words where the value is > 1.
Was This Post Helpful? 0
  • +
  • -

#3 cbeier8629  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 09-November 12

Re: nested loop array search for repeated words

Posted 10 November 2012 - 04:57 AM

never used dictionary before, anyway you can help me a little with the code starting off?
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,090
  • Joined: 02-July 08

Re: nested loop array search for repeated words

Posted 10 November 2012 - 08:20 AM

The second sentence I wrote is pseudo code for your loading of the Dictionary. Give it a try.

For Each word As String In words
  'use the logic I wrote above to add keys or values
Next

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1