Professional Web Applications Themes

identify duplicates in an array and number of times duplicated - ASP

hi, i have created an array from recordset containing user names eg. (davidp, davidp, evenf, patricka, rebeccah) which i have sorted in alphabetical order, but i need to identify duplicates in this array and the number of times it has been duplicated. can someone help? -- Michelle...

  1. #1

    Default identify duplicates in an array and number of times duplicated

    hi,

    i have created an array from recordset containing user names
    eg. (davidp, davidp, evenf, patricka, rebeccah)

    which i have sorted in alphabetical order, but i need to
    identify duplicates in this array and the number of times it has
    been duplicated.

    can someone help?

    --
    Michelle



    Michelle Guest

  2. #2

    Default Re: identify duplicates in an array and number of times duplicated

    If you've already sorted your array alphabetically, you can do:

    Dim sCurVal, sLastVal, iDups
    iDups = 0
    For i = LBound(YourArray) To UBound(YourArray)
    sCurVal = YourArray(i)
    If sCurVal = sLastVal Then iDups = iDups + 1
    sLastVal = sCurVal
    Next


    This will just give you the total number of duplicate items, like, if your
    array is

    a,b,c,c,d,e,e,e,f,g

    iDups will return as 3, since there is one extra c and two extra e's.

    Is that what you wanted, or did you want to be able to say:
    c has 1 duplicate
    e has two duplicates
    etc.

    Ray at work





    "Michelle" <abchotmail.com> wrote in message
    news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    > hi,
    >
    > i have created an array from recordset containing user names
    > eg. (davidp, davidp, evenf, patricka, rebeccah)
    >
    > which i have sorted in alphabetical order, but i need to
    > identify duplicates in this array and the number of times it has
    > been duplicated.
    >
    > can someone help?
    >
    > --
    > Michelle
    >
    >
    >

    Ray at Guest

  3. #3

    Default Re: identify duplicates in an array and number of times duplicated

    Why not do a count in the SQL query string and get the username and count from the recordset?



    -------------------------------------------------
    d l b j r

    Unambit from meager knowledge of inane others,
    engender uncharted sagacity.
    -------------------------------------------------


    dlbjr Guest

  4. #4

    Default Re: identify duplicates in an array and number of times duplicated

    You'd be better off getting another recordset with the duplicate counts
    already created for you?

    SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    FROM YourTable
    GROUP BY [Name]
    ORDER BY Count([Name]) DESC

    This will give you:

    UserName CountOfUserName
    Chris 10
    Dave 7
    Henrik 2
    Michale 1
    Joan 1

    etc.

    If you only want the duplicates listed then change it to be:

    SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    FROM YourTable
    WHERE Count([Name]) > 1
    GROUP BY [Name]
    ORDER BY Count([Name]) DESC

    Hope this helps.

    Chris.

    "Michelle" <abchotmail.com> wrote in message
    news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    hi,

    i have created an array from recordset containing user names
    eg. (davidp, davidp, evenf, patricka, rebeccah)

    which i have sorted in alphabetical order, but i need to
    identify duplicates in this array and the number of times it has
    been duplicated.

    can someone help?

    --
    Michelle




    Chris Barber Guest

  5. #5

    Default Re: identify duplicates in an array and number of times duplicated

    Hi Ray
    > Is that what you wanted, or did you want to be able to say:
    > c has 1 duplicate
    > e has two duplicates
    Yes this is what i want

    I tried to use your code, although i had to add 'end if', it gave me a
    a 'Subscript out of range' error at
    >sCurVal = YourArray(i)
    ----------------------------------------------
    this is my code for the array
    ----------------------------------------------
    <%
    Dim MyArray, sOutput
    MyArray = rs.GetRows()
    MyArray = arraysort(MyArray)

    Dim iRowLoop
    For iRowLoop = 0 to UBound(MyArray, 2)
    sOutput = trim(left(MyArray(iColLoop, iRowLoop),10)) & "<br> "
    Response.Write(sOutput)
    Next
    %>
    ----------------------------------------------

    Actually the rows in the array is unique, the source is a text file dump of
    terminal service processes, but i need to extract the user names of those
    using a particular process twice, and how many times they have these
    processes open. I cannot sort or search for duplicates in SQL, because the
    first line contains a lot of spaces inbetween the headings which dosnt make
    a qualified column name.

    Hope you can help.

    --
    Michelle


    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:#CzQWeDWDHA.2352TK2MSFTNGP12.phx.gbl...
    > If you've already sorted your array alphabetically, you can do:
    >
    > Dim sCurVal, sLastVal, iDups
    > iDups = 0
    > For i = LBound(YourArray) To UBound(YourArray)
    > sCurVal = YourArray(i)
    > If sCurVal = sLastVal Then iDups = iDups + 1
    > sLastVal = sCurVal
    > Next
    >
    >
    > This will just give you the total number of duplicate items, like, if your
    > array is
    >
    > a,b,c,c,d,e,e,e,f,g
    >
    > iDups will return as 3, since there is one extra c and two extra e's.
    >
    > Is that what you wanted, or did you want to be able to say:
    > c has 1 duplicate
    > e has two duplicates
    > etc.
    >
    > Ray at work
    >
    >
    >
    >
    >
    > "Michelle" <abchotmail.com> wrote in message
    > news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    > > hi,
    > >
    > > i have created an array from recordset containing user names
    > > eg. (davidp, davidp, evenf, patricka, rebeccah)
    > >
    > > which i have sorted in alphabetical order, but i need to
    > > identify duplicates in this array and the number of times it has
    > > been duplicated.
    > >
    > > can someone help?
    > >
    > > --
    > > Michelle
    > >
    > >
    > >
    >
    >

    Michelle Guest

  6. #6

    Default Re: identify duplicates in an array and number of times duplicated

    Re:
    I cannot sort or search for duplicates in SQL, because the
    first line contains a lot of spaces in-between the headings which doesn't
    make
    a qualified column name.

    That doesn't seem to make sense - in order to get a recordset you must be
    specifying some SQL? You can determine the 'real' field names by enumerating
    the fields collection or just use the numeric field indexes 0 to however
    many fields.

    eg. SELECT TOP 1 * FROM Table

    will get a single row recordset that you can look at to get the field names.

    However, you know what you have so I'll stop there and let you decide what's
    easiest to implement (array manipulation or SQL).

    Chris.

    "Michelle" <abchotmail.com> wrote in message
    news:3f2b1843$0$10355$afc38c87news.optusnet.com.a u...
    Please see reply to Ray

    --
    Michelle



    "Chris Barber" <chrisblue-canoe.co.uk.NOSPAM> wrote in message
    news:OW1OPJIWDHA.1896TK2MSFTNGP12.phx.gbl...
    > You'd be better off getting another recordset with the duplicate counts
    > already created for you?
    >
    > SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    > FROM YourTable
    > GROUP BY [Name]
    > ORDER BY Count([Name]) DESC
    >
    > This will give you:
    >
    > UserName CountOfUserName
    > Chris 10
    > Dave 7
    > Henrik 2
    > Michale 1
    > Joan 1
    >
    > etc.
    >
    > If you only want the duplicates listed then change it to be:
    >
    > SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    > FROM YourTable
    > WHERE Count([Name]) > 1
    > GROUP BY [Name]
    > ORDER BY Count([Name]) DESC
    >
    > Hope this helps.
    >
    > Chris.
    >
    > "Michelle" <abchotmail.com> wrote in message
    > news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    > hi,
    >
    > i have created an array from recordset containing user names
    > eg. (davidp, davidp, evenf, patricka, rebeccah)
    >
    > which i have sorted in alphabetical order, but i need to
    > identify duplicates in this array and the number of times it has
    > been duplicated.
    >
    > can someone help?
    >
    > --
    > Michelle
    >
    >
    >
    >


    Chris Barber Guest

  7. #7

    Default Re: identify duplicates in an array and number of times duplicated

    Hi Chris

    This is the SQL i am using
    > sql="SELECT * from process.txt"
    process.txt is a text file dumped from ms-dos and this is the first 6 lines
    from this file
    --------------------------------------------------------
    USERNAME SESSIONNAME ID PID IMAGE
    davidp id 1 1 3472 notepad.exe
    davidp id 9 9 4348 notepad.exe
    evenf id 8 8 5160 notepad.exe
    patricka id 19 19 7904 notepad.exe
    rebeccah id 10 10 2820 notepad.exe
    --------------------------------------------------------
    since this file isnt delimited, all this data is retrieved into one column
    and the first line contains spaces, so i cannot do

    sql="SELECT 'USERNAME SESSIONNAME ID PID IMAGE'
    from process.txt"
    or any other sql statement that requires i directly name the column
    >You can determine the 'real' field names by enumerating
    > the fields collection or just use the numeric field indexes 0 to however
    how can i do this in ASP?

    I want to be able to show that davidp is using a program twice
    eg. davidp (2)

    --
    Michelle


    "Chris Barber" <chrisblue-canoe.co.uk.NOSPAM> wrote in message
    news:uveRNsJWDHA.3220tk2msftngp13.phx.gbl...
    > Re:
    > I cannot sort or search for duplicates in SQL, because the
    > first line contains a lot of spaces in-between the headings which doesn't
    > make
    > a qualified column name.
    >
    > That doesn't seem to make sense - in order to get a recordset you must be
    > specifying some SQL? You can determine the 'real' field names by
    enumerating
    > the fields collection or just use the numeric field indexes 0 to however
    > many fields.
    >
    > eg. SELECT TOP 1 * FROM Table
    >
    > will get a single row recordset that you can look at to get the field
    names.
    >
    > However, you know what you have so I'll stop there and let you decide
    what's
    > easiest to implement (array manipulation or SQL).
    >
    > Chris.
    >
    > "Michelle" <abchotmail.com> wrote in message
    > news:3f2b1843$0$10355$afc38c87news.optusnet.com.a u...
    > Please see reply to Ray
    >
    > --
    > Michelle
    >
    >
    >
    > "Chris Barber" <chrisblue-canoe.co.uk.NOSPAM> wrote in message
    > news:OW1OPJIWDHA.1896TK2MSFTNGP12.phx.gbl...
    > > You'd be better off getting another recordset with the duplicate counts
    > > already created for you?
    > >
    > > SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    > > FROM YourTable
    > > GROUP BY [Name]
    > > ORDER BY Count([Name]) DESC
    > >
    > > This will give you:
    > >
    > > UserName CountOfUserName
    > > Chris 10
    > > Dave 7
    > > Henrik 2
    > > Michale 1
    > > Joan 1
    > >
    > > etc.
    > >
    > > If you only want the duplicates listed then change it to be:
    > >
    > > SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    > > FROM YourTable
    > > WHERE Count([Name]) > 1
    > > GROUP BY [Name]
    > > ORDER BY Count([Name]) DESC
    > >
    > > Hope this helps.
    > >
    > > Chris.
    > >
    > > "Michelle" <abchotmail.com> wrote in message
    > > news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    > > hi,
    > >
    > > i have created an array from recordset containing user names
    > > eg. (davidp, davidp, evenf, patricka, rebeccah)
    > >
    > > which i have sorted in alphabetical order, but i need to
    > > identify duplicates in this array and the number of times it has
    > > been duplicated.
    > >
    > > can someone help?
    > >
    > > --
    > > Michelle
    > >
    > >
    > >
    > >
    >
    >
    >

    Michelle Guest

  8. #8

    Default Re: identify duplicates in an array and number of times duplicated

    Hi All

    Thank you for your inputs, but i have solved my problem,
    i didnt ask the right question in the beginning, what i needed was
    to search a string for duplicates and the number of times the value
    had been duplicated.

    But what i had was, an array of unique values, which i manipulated
    and displayed to show some duplicates.

    Thanks again.
    --
    Michelle


    "Michelle" <abchotmail.com> wrote in message
    news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    > hi,
    >
    > i have created an array from recordset containing user names
    > eg. (davidp, davidp, evenf, patricka, rebeccah)
    >
    > which i have sorted in alphabetical order, but i need to
    > identify duplicates in this array and the number of times it has
    > been duplicated.
    >
    > can someone help?
    >
    > --
    > Michelle
    >
    >
    >

    Michelle Guest

  9. #9

    Default Re: identify duplicates in an array and number of times duplicated

    Perhaps this is space or fixed width delimited?
    It is possible to query a text file that is space or fixed width delimited
    by column names but I'm pretty sure you're already aware of that and may
    even have tried it.

    Cheers,

    Chris.

    "Michelle" <abchotmail.com> wrote in message
    news:3f2b276e$0$10357$afc38c87news.optusnet.com.a u...
    Hi Chris

    This is the SQL i am using
    > sql="SELECT * from process.txt"
    process.txt is a text file dumped from ms-dos and this is the first 6 lines
    from this file
    --------------------------------------------------------
    USERNAME SESSIONNAME ID PID IMAGE
    davidp id 1 1 3472 notepad.exe
    davidp id 9 9 4348 notepad.exe
    evenf id 8 8 5160 notepad.exe
    patricka id 19 19 7904 notepad.exe
    rebeccah id 10 10 2820 notepad.exe
    --------------------------------------------------------
    since this file isnt delimited, all this data is retrieved into one column
    and the first line contains spaces, so i cannot do

    sql="SELECT 'USERNAME SESSIONNAME ID PID IMAGE'
    from process.txt"
    or any other sql statement that requires i directly name the column
    >You can determine the 'real' field names by enumerating
    > the fields collection or just use the numeric field indexes 0 to however
    how can i do this in ASP?

    I want to be able to show that davidp is using a program twice
    eg. davidp (2)

    --
    Michelle


    "Chris Barber" <chrisblue-canoe.co.uk.NOSPAM> wrote in message
    news:uveRNsJWDHA.3220tk2msftngp13.phx.gbl...
    > Re:
    > I cannot sort or search for duplicates in SQL, because the
    > first line contains a lot of spaces in-between the headings which doesn't
    > make
    > a qualified column name.
    >
    > That doesn't seem to make sense - in order to get a recordset you must be
    > specifying some SQL? You can determine the 'real' field names by
    enumerating
    > the fields collection or just use the numeric field indexes 0 to however
    > many fields.
    >
    > eg. SELECT TOP 1 * FROM Table
    >
    > will get a single row recordset that you can look at to get the field
    names.
    >
    > However, you know what you have so I'll stop there and let you decide
    what's
    > easiest to implement (array manipulation or SQL).
    >
    > Chris.
    >
    > "Michelle" <abchotmail.com> wrote in message
    > news:3f2b1843$0$10355$afc38c87news.optusnet.com.a u...
    > Please see reply to Ray
    >
    > --
    > Michelle
    >
    >
    >
    > "Chris Barber" <chrisblue-canoe.co.uk.NOSPAM> wrote in message
    > news:OW1OPJIWDHA.1896TK2MSFTNGP12.phx.gbl...
    > > You'd be better off getting another recordset with the duplicate counts
    > > already created for you?
    > >
    > > SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    > > FROM YourTable
    > > GROUP BY [Name]
    > > ORDER BY Count([Name]) DESC
    > >
    > > This will give you:
    > >
    > > UserName CountOfUserName
    > > Chris 10
    > > Dave 7
    > > Henrik 2
    > > Michale 1
    > > Joan 1
    > >
    > > etc.
    > >
    > > If you only want the duplicates listed then change it to be:
    > >
    > > SELECT [Name] as UserName, Count([Name]) as CountOfUserName
    > > FROM YourTable
    > > WHERE Count([Name]) > 1
    > > GROUP BY [Name]
    > > ORDER BY Count([Name]) DESC
    > >
    > > Hope this helps.
    > >
    > > Chris.
    > >
    > > "Michelle" <abchotmail.com> wrote in message
    > > news:3f2a7499$0$10354$afc38c87news.optusnet.com.a u...
    > > hi,
    > >
    > > i have created an array from recordset containing user names
    > > eg. (davidp, davidp, evenf, patricka, rebeccah)
    > >
    > > which i have sorted in alphabetical order, but i need to
    > > identify duplicates in this array and the number of times it has
    > > been duplicated.
    > >
    > > can someone help?
    > >
    > > --
    > > Michelle
    > >
    > >
    > >
    > >
    >
    >
    >


    Chris Barber Guest

Similar Threads

  1. Number of times visited
    By ed@oac in forum Coldfusion Database Access
    Replies: 3
    Last Post: February 17th, 11:44 AM
  2. setting number of times Flash plays
    By LauraK in forum Macromedia Flash
    Replies: 2
    Last Post: January 2nd, 11:56 PM
  3. howto put the same number 36 times in a list?
    By Robert in forum Macromedia Director Lingo
    Replies: 2
    Last Post: December 9th, 11:22 AM
  4. Identify credit card types based on thier number
    By proterm in forum FileMaker
    Replies: 4
    Last Post: September 15th, 11:14 PM
  5. search for duplicates and sort array
    By Benjamin Goldberg in forum PERL Miscellaneous
    Replies: 2
    Last Post: August 27th, 03:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139