Jump to content

Show all Unique Strings?


 Share

Recommended Posts

I would think this would be easy to do, but I can't think of where to begin. Can someone help me out?

Problem:

Have a list of 1000+ category names, that I would like to condense, and display without any duplicates. So the script would output 70+ category names that were all unique, without any duplicates. For instance, the list below shows how the categories currently would appear, and below them is the final result I desire.

The list is currently in cells in an Excel file, but I could put them into Notepad, or whatever would work best.

Thanks in Advance.

Current:

ATV Tours

ATV Tours

ATV Tours

Back Country Skiing

Back Country Skiing

Bicycle Tours & Mountain Biking

Bicycle Tours & Mountain Biking

Bicycle Tours & Mountain Biking

Bicycle Tours & Mountain Biking

Bicycle Tours & Mountain Biking

Final:

ATV Tours

Back Country Skiing

Bicycle Tours & Mountain Biking

Link to comment
Share on other sites

  • Moderators

Just read them into an array, and use something like one of these 2 methods:

http://www.autoitscript.com/forum/index.ph...st&p=245675

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Just read them into an array, and use something like one of these 2 methods:

http://www.autoitscript.com/forum/index.ph...st&p=245675

I admit I am a little lost still, but here is what I have come up with. I am not even sure this is returning the solution, but I did my best trying to modify what I saw on your post.

How do I display the results, and say, print them to a text file in the script directory?

#include <File.au3>
Global $aArray

$sFilePath = @ScriptDir & "\" & "All_Live_Categories.txt"
$iBase = 1
$iUnique = 1

_FileReadToArray($sFilePath, $aArray)
_ArrayUnique ($aArray, @CRLF, $iBase, $iUnique)

Func _ArrayUnique(ByRef $aArray, $vDelim, $iBase, $iUnique)
    If $vDelim = @CRLF Then $vDelim = Chr(01)
    Local $sHold
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iUnique) Then _
            $sHold &= $aArray[$iCC] & $vDelim
    Next
    Return StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
EndFunc
Link to comment
Share on other sites

  • Moderators

I admit I am a little lost still, but here is what I have come up with. I am not even sure this is returning the solution, but I did my best trying to modify what I saw on your post.

How do I display the results, and say, print them to a text file in the script directory?

#include <File.au3>
Global $aArray

$sFilePath = @ScriptDir & "\" & "All_Live_Categories.txt"
$iBase = 1
$iUnique = 1

_FileReadToArray($sFilePath, $aArray)
_ArrayUnique ($aArray, @CRLF, $iBase, $iUnique)

Func _ArrayUnique(ByRef $aArray, $vDelim, $iBase, $iUnique)
    If $vDelim = @CRLF Then $vDelim = Chr(01)
    Local $sHold
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iUnique) Then _
            $sHold &= $aArray[$iCC] & $vDelim
    Next
    Return StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
EndFuncoÝ÷ Ûú®¢×¢êî²)ධ®à{¦¦W­ìË*.®ë"­N­­ën®{ªëk(­±é_Â+a¶®*®zËkx,{ayªëk&(»e§¶Ú.±ëaɨ­ëajybérjëh×6#include <array.au3>;for _ArrayDisplay only
Global $aArray

$sFilePath = @ScriptDir & "\" & "All_Live_Categories.txt"
$iBase = 1
$iUnique = 1

$aArray = StringSplit(StringStripCR(FileRead($sFilePath)), @LF)
_ArrayDisplay($aArray, 'Non-Unique')
_ArrayUnique ($aArray, @LF, $iBase, $iUnique)
_ArrayDisplay($aArray, 'Unique Strings')

Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 1, $iCase = 1)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If $vDelim = '' Then $vDelim = Chr(01)
    Local $sHold
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iCase) Then _
            $sHold &= $aArray[$iCC] & $vDelim
    Next
    If $sHold Then
        $aArray = StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
        Return SetError(0, 0, 0)
    EndIf
    Return SetError(2, 0, 0)
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hey there.

Brand new here in the forum. This post catched my eye. So here is my first contribution to the community (possibly?!?) :">

litlmike: since you ask for a "simple" solution to making your categories unique: In Excel you can extract the unique items to a new list using menu Data > Filter > Advanced

filter and check "unique items only".

Will this possibly help?

cheers

Tank

Link to comment
Share on other sites

I would think this would be easy to do, but I can't think of where to begin. Can someone help me out?

use the Hash Table UDF http://www.autoitscript.com/forum/index.ph...mp;hl=hash++udf

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Your using the wrong example the way your using it. That returns an array itself with the unique strings in the array.

You'll want to use this more than likely.

Thanks for the feedback, and help on this. Below is the final script.

@Tankard

Thanks for letting me know about the Excel Filter, but I would think I was cheating! I actually tried it out, but it still returned some duplicates. This actually seemed more reliable.

Thanks everyone.

#include <array.au3>;for _ArrayDisplay only
#include <File.au3>
Global $aArray

$sFilePath = @ScriptDir & "\" & "All_Live_Categories.txt"
$sFilePath2 = @ScriptDir & "\" & "All_Live_Categories2.txt"
$iBase = 1
$iUnique = 1

$aArray = StringSplit(StringStripCR(FileRead($sFilePath)), @LF)
;~ _ArrayDisplay($aArray, 'Non-Unique')
_ArrayUnique ($aArray, @LF, $iBase, $iUnique)
;~ _ArrayDisplay($aArray, 'Unique Strings')
_FileWriteFromArray($sFilePath2, $aArray)
If @error = 2 Then
    MsgBox (0, "", "Error!" & " @error = " & @error & @CRLF & "2 = Input is not an Array", 5)
ElseIf @error = 1 Then
    MsgBox (0, "", " Error!" & " @error = " & @error & @CRLF & "1 = Error opening specified file", 5)   
    
EndIf

Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 1, $iCase = 1)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If $vDelim = '' Then $vDelim = Chr(01)
    Local $sHold
    For $iCC = $iBase To UBound($aArray) - 1
        If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iCase) Then _
            $sHold &= $aArray[$iCC] & $vDelim
    Next
    If $sHold Then
        $aArray = StringSplit(StringTrimRight($sHold, StringLen($vDelim)), $vDelim)
        Return SetError(0, 0, 0)
    EndIf
    Return SetError(2, 0, 0)
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...