Jump to content

Building Unique String Return From Array ~ Problem


Recommended Posts

Please help, I can't get the Function to return all Unique items in an array as a string

What I'm expecting is:

"Rock|Dance|Indi|2009|Dance|Electro|Playlist"

Functional Code Snippet:

#include <Array.au3>
#include <Debug.au3>
#NoTrayIcon
_DebugSetup ( "debug" )

Local $avArray[6]
$avArray[0] = "Rock"
$avArray[1] = "Dance"
$avArray[2] = "Indi, 2009, Dance"
$avArray[3] = "Electro, 2009"
$avArray[4] = "Indi"
$avArray[5] = "Playlist"

_DebugOut(@CRLF & "return; " & BuildTagList($avArray), 1)

;// Build Unique List of all Tags //
Func BuildTagList($arrayIn)
Dim $returnString
$tagsUniqueArray = _ArrayUnique($arrayIn)

For $x = 1 To UBound($tagsUniqueArray) - 1
    _DebugOut("x- " & $tagsUniqueArray[$x], 1)
    $splitArray = StringSplit($tagsUniqueArray,",")
    For $y = 1 To UBound($splitArray) - 1
            _DebugOut("y- " & $splitArray[$y], 1)
            $returnString = $returnString & Trim($splitArray[$y]) & "|"
    Next
Next

Return $returnString
    
EndFunc

;// Strip Leading and Trailing White Space //
Func Trim($strIn)
    return StringStripWS(StringStripWS($strIn, 1), 2)
EndFunc

With Thanks,

=|)arkSprout=

=|)arkSprout=VBA | VBScript | C# Programmer [font="Verdana"]"Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."[/font]
Link to comment
Share on other sites

  • Developers

This line:

$splitArray = StringSplit($tagsUniqueArray, ",")

Should be

$splitArray = StringSplit($tagsUniqueArray[$x], ",")

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This line:

$splitArray = StringSplit($tagsUniqueArray, ",")

Should be

$splitArray = StringSplit($tagsUniqueArray[$x], ",")

With great thanks, I've been looking at this for hours...

I got and output of:

|Rock|Dance|Indi|2009|Dance|Electro|Indi|Playlist|

All I've got to do now, is remove the trailing and leading I-Bars.

Again, Jos ~ Thanks.

=|)arkSprout=

Edited by DarkSprout
=|)arkSprout=VBA | VBScript | C# Programmer [font="Verdana"]"Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."[/font]
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...