Split Strings?

var idPage:Array = [];

function checkCategory(category:String, object:Object):Void {
    if (idPage[category]) {
        idPage[category].push(object);

        // insert the new item into the category list
    } else {
        // category DOES NOT exist
        idPage[category] = [object];

        // create an array and insert the object 
    }
}

//objects
checkCategory("google",{title:"google", links:"http://www.google.com", date:"20060215"});
checkCategory("yahoo",{title:"yahoo", links:"http://www.yahoo.com", date:"20070123"});
checkCategory("microsoft",{title:"vista", links:"http://www.microsoft.com", date:"20070521"});
checkCategory("yahoo",{title:"flickr", links:"http://www.flickr.com", date:"20070607"});
checkCategory("google", {title:"youtube", links:"http://www.youtube.com", date:"20070712"});
checkCategory("yahoo||ludricorp",{title:"del.icio.us", links:"http://del.icio.us", date:"20051011"});
checkCategory("google||pyralabs",{title:"blogspot", links:"http://www.blogspot.com", date:"20060215"});

//
for (var categoryList in idPage){
    trace("+ "+categoryList)
    
for(var catTitle in idPage[categoryList]) {
    trace("  -   "+ idPage[categoryList][catTitle].title)
    
}

//out put
+ google||pyralabs
  -   blogspot
+ yahoo||ludricorp
  -   del.icio.us
+ microsoft
  -   vista
+ yahoo
  -   flickr
  -   yahoo
+ google
  -   youtube
  -   google

}

Hi… I need some direction… how do I spilt the google||pyralabs and yahoo||ludricorp into it’s own string and if they have the same string, then will merge with it? Wanting to get the output into this

+ pyralabs
  -   blogspot
+ ludricorp
  -   del.icio.us
+ microsoft
  -   vista
+ yahoo
  -   flickr
  -   yahoo
   -   del.icio.us
+ google
  -   youtube
  -   google
  -   blogspot

Please?

function checkCategory(category:String, object:Object):Void {
	if (idPage[category]) {
		// category exists
		var multiCategories:Array = category.split("||");
		//for (var i = 0; i<multiCategories.length; i++){
			//trace(multiCategories*);
		multiCategories[category].push(objects);
		//idPage[category].push(object);

		// insert the new item into the category list
	} else {
		// category DOES NOT exist
		idPage[category] = [object];

		// create an array and insert the object 
	}
}

Output:


+ google||pyralabs
  -   blogspot
+ yahoo||ludricorp
  -   del.icio.us
+ microsoft
  -   vista
+ yahoo
  -   yahoo
+ google
  -   google

Where did I go wrong?


function checkCategory(category:String, object:Object):Void {
    var mCat:Array = category.split("||");
    for(var i:Number = 0;i<mCat.length;i++){ 
        // Loop through ALL the strings
        if (idPage[mCat*]) { 
            // category exists
            idPage[mCat*].push(object); 
            // insert the new item into the category list
        } else { 
            // category DOES NOT exist
            idPage[mCat*] = [object]; 
            // create an array and insert the object
        }
    }
}

I haven’t tested it, but I think this should do the trick.

awesome.
it works great. thank you! :wink: