# Split Strings?

**URL:** https://forum.kirupa.com/t/split-strings/259765
**Category:** flash
**Created:** [May 8, 2008, 3:23pm UTC](https://forum.kirupa.com/t/split-strings/259765 "2008-05-08T15:23:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fenrost](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fenrost/32/2470_2.png) [@fenrost](https://forum.kirupa.com/u/fenrost)
#### Post date: [May 8, 2008, 3:23pm UTC](https://forum.kirupa.com/t/split-strings/259765/1 "2008-05-08T15:23:56Z")

</div>

```php
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

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

```

Please?

---

<div class="post-metadata">

### Author: ![fenrost](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fenrost/32/2470_2.png) [@fenrost](https://forum.kirupa.com/u/fenrost)
#### Post date: [May 8, 2008, 10:14pm UTC](https://forum.kirupa.com/t/split-strings/259765/2 "2008-05-08T22:14:23Z")

</div>

```php
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:

```php

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

```

Where did I go wrong?

---

<div class="post-metadata">

### Author: ![Valaran](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@Valaran](https://forum.kirupa.com/u/Valaran)
#### Post date: [May 9, 2008, 4:43am UTC](https://forum.kirupa.com/t/split-strings/259765/3 "2008-05-09T04:43:57Z")

</div>

```auto

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.

---

<div class="post-metadata">

### Author: ![fenrost](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/fenrost/32/2470_2.png) [@fenrost](https://forum.kirupa.com/u/fenrost)
#### Post date: [May 10, 2008, 7:43am UTC](https://forum.kirupa.com/t/split-strings/259765/4 "2008-05-10T07:43:07Z")

</div>

awesome.  
it works great. thank you! 😉
