# Substring searching text prevent finding duplicates

**URL:** <https://forum.kirupa.com/t/substring-searching-text-prevent-finding-duplicates/241883>\
**Category:** Uncategorized\
**Created:** [October 19, 2007, 3:33am UTC](https://forum.kirupa.com/t/substring-searching-text-prevent-finding-duplicates/241883 "2007-10-19T03:33:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arandlett](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@arandlett](https://forum.kirupa.com/u/arandlett)\
**Post date:** [October 19, 2007, 3:33am UTC](https://forum.kirupa.com/t/substring-searching-text-prevent-finding-duplicates/241883/1 "2007-10-19T03:33:22Z")

</div>

have a function that sends a search term, xmllist & content to be searched (with indexes at end of each line to represent item in xmllist). the function then outputs and xmllist of the found nodes that have the search term in them however if the the text in the node has two or more words that are the same it will add that node however many times that word appears.

How do I prevent this. I have attached the code.

```auto
function searchStringInAttribute(list:XMLList, attributelist:String, term:String):XMLList {
	var output:XMLList = new XMLList();
	var i:Number = 0;
	var pos:Number = 0;
	var index:int = 0;
	var count:int = 0;
	while (i > -1) {
		pos = attributelist.indexOf(term, i);
		if (pos > -1) {
			index = int( attributelist.substring(attributelist.indexOf("<", pos)+1, attributelist.indexOf(">", pos)) );
			output[count] = list[index];
			count++;
			i = pos+term.length;
		} else {
			i = pos;
		}
	}
	return output;
}

```
