Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing duplicate from string (must be compatible with IE on Mac)

Status
Not open for further replies.

vasilek

Programmer
Jan 5, 2003
99
US
Hello. This is my third post on this topic. I got great replies on how to remove duplicates from the string. But unfortunately all of them are not working in IE on Mac OS9. Here is what I've been using so far. And it works great in IE and Netscape on Windows platform but doesn't work in IE5.1 on Mac OS9. Can someone help me with Mac/Windows compatible code. May be the simpler way of doing it will work, if there is such. Thanks.

____________________________________________________
Array.prototype.removeDuplicates = function()
{
var newArray = new Array();
for (var i = 0; i < this.length; i++)
{
if (!newArray.contains(this))
{
newArray.push(this)
}
}
this.length = 0;
for (var i = 0; i < newArray.length; i++)
{
this.push(newArray)
}
return this;
}

Array.prototype.contains = function(elm)
{
var len = this.length;
for (var i = 0; i < len; i++)
{
if (this == elm)
{
return true
}
}
return false
}
 
send it to the server, do it there send it back - no browser or operating system problems.
 
vasilek,

I don't understand what is up with the &quot;MAC&quot; environ and
arrays, evidently it doesn't like methods that we consider
established, like push or splice.

I built this mostly based on the string output, tested it
on OS9 IE5 and it did it's work try it out.

And did you notice how even the &quot;tek-tips&quot; site is all
chopped up with the &quot;IE5&quot;...the dropdown logon div is
completely black all the way down the screen.

People that use this browser must get used to seeing stuff
like that though.

Try it out, let me know if this works in 5.1 ....
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html><head><title>TEST</title><script>
function strpdup(str){
ckarr = str.split(&quot; &quot;);
 for(j=0;j<ckarr.length;j++){
   retmp = new RegExp(ckarr[j],&quot;ig&quot;);
   found = str.match(retmp);
   if(found && found.length > 1){
   retmp = new RegExp(ckarr[j],&quot;i&quot;);
   str = str.replace(retmp,'%');} }
   str = str.replace(/%\s/g,&quot;&quot;);
   nwarr = str.split(&quot; &quot;);
   alert(nwarr);
   alert(nwarr.join(&quot; &quot;));
 document.getElementById('output').value = nwarr.join(&quot; &quot;);  
}
</script></head><body>
<input type=&quot;text&quot; name=&quot;input&quot; size=&quot;40&quot; onBlur=&quot;strpdup(this.value);&quot;
value=&quot;val1 val2 val3 val2 val4 val1 val5&quot;>
<br><input type=&quot;text&quot; id=&quot;output&quot; size=&quot;40&quot;>
</body></html>

2b||!2b
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top