473,396 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

No Duplicates Script

I,m looking for a script to remove duplicates email addresses from a
list, the addresses will be displayed one per line in a textarea. The
script will be used on a simple webtv browser. Thanks Joe

Jul 23 '05 #1
5 1392
"Papajo" <do*****@webtv.net> wrote in message
news:75***************@storefull-3331.bay.webtv.net...
I,m looking for a script to remove duplicates email addresses from a
list, the addresses will be displayed one per line in a textarea. The
script will be used on a simple webtv browser. Thanks Joe


It's unlikely you'll find any generic script to do this, but it should
be simple enough to write something yourself that does this.

<form name="testForm">
<textarea name="testTextarea" rows="10">
ab*@def.com
de*@ghi.com
gh*@jkl.com
ab*@def.com
jk*@mno.com
mn*@pqr.com
gh*@jkl.com
pq*@stu.com
st*@vwx.com
ab*@def.com
</textarea>
<input type="button" name="testButton" value="Remove duplicates"
onclick="removeDuplicateLines(this.form['testTextarea']);">
</form>
<script type="text/javascript">
function removeDuplicateLines(ta) {
var lines = ta.value.replace(/\r/g, '\n').split(/\n+/);
var addresses = {};
for (var ii = 0; ii < lines.length; ++ii) {
if (addresses[lines[ii]]) {
lines.splice(ii, 1);
} else {
addresses[lines[ii]] = true;
}
}
ta.value = lines.join('\n');
}
</script>

_Appears_ to work, but not fully tested. Also, if the E-mail addresses
differ in any way (case, extra whitespace at the beginning or end) this
function will not detect them as duplicates.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:03*************@news2.mts.net...
"Papajo" <do*****@webtv.net> wrote in message
news:75***************@storefull-3331.bay.webtv.net...
I,m looking for a script to remove duplicates email addresses from a
list, the addresses will be displayed one per line in a textarea. The
script will be used on a simple webtv browser. Thanks Joe


It's unlikely you'll find any generic script to do this, but it should
be simple enough to write something yourself that does this.

<form name="testForm">
<textarea name="testTextarea" rows="10">
ab*@def.com
de*@ghi.com
gh*@jkl.com
ab*@def.com
jk*@mno.com
mn*@pqr.com
gh*@jkl.com
pq*@stu.com
st*@vwx.com
ab*@def.com
</textarea>
<input type="button" name="testButton" value="Remove duplicates"
onclick="removeDuplicateLines(this.form['testTextarea']);">
</form>
<script type="text/javascript">
function removeDuplicateLines(ta) {
var lines = ta.value.replace(/\r/g, '\n').split(/\n+/);
var addresses = {};
for (var ii = 0; ii < lines.length; ++ii) {
if (addresses[lines[ii]]) {
lines.splice(ii, 1);
} else {
addresses[lines[ii]] = true;
}


Oops, should probably be:

var ii = 0;
while (ii < lines.length) {
if (addresses[lines[ii]]) {
lines.splice(ii, 1);
} else {
addresses[lines[ii]] = true;
++ii;
}
}

Still not fully tested, I'm not sure what happens when all the items in
the list are duplicates of each other for example.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
JRS: In article <75***************@storefull-3331.bay.webtv.net>, dated
Fri, 10 Jun 2005 17:35:37, seen in news:comp.lang.javascript, Papajo
<do*****@webtv.net> posted :
I,m looking for a script to remove duplicates email addresses from a
list, the addresses will be displayed one per line in a textarea. The
script will be used on a simple webtv browser. Thanks Joe


I know little of WebTV, but the obvious way would be :-

(1) Tidy the entries, if applicable, by removing such as leading or
trailing whitespace.

(2) Split the textarea at newlines

(3) Sort

(4) Scan, copying to a new list only those differing from their
predecessor.

The following was written in a textarea F.Code (in js-quick.htm), and
eval() was applied to F.Code.value; the result looked as required.

// aaa
// ccc
var Y = [], Last, Z, j, X = F.Code.value.split(/[\r\n]+/).sort()
for (j=0; j<X.length; j++) if (Last!=X[j]) Y[Y.length] = Last = X[j]
// aaa
Y = Y.join("\n")
F.Code.value=Y

Note that the non-comment lines are in alphabetical order, so that the
code does not rearrange itself.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
Thank you for your help but webtv doesn't support either of the examples
you came up with, webtv has a lot of limitations.
Joe

Jul 23 '05 #5
Papajo wrote:
Thank you for your help but webtv doesn't support either of the
examples you came up with, webtv has a lot of limitations.


Why did not you say that in the first place? And what part(s) of
the presented scripts do(es) not work (and how don't they), exactly?
PointedEars
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bellefy | last post by:
Hi All, I have a fairly large table with approx 30K rows that updates every night via a cron script that automatically downloads the 2 new csv's. The problem is the files are downloaded from...
6
by: Marlene | last post by:
Hi All I have the following scenario, where I have found all the duplicates in a table, based on an order number and a part number (item).I might have something like this: Order PODate Rec...
3
by: AK | last post by:
Hi Our product uses MS-SQL Server 2000. One of our customer has 10 installations with each installation stroring data in its own database. Now the customer wants to consolidate these databases...
4
by: Mokita | last post by:
Hello, I am working with Taverna to build a workflow. Taverna has a beanshell where I can program in java. I am having some problems in writing a script, where I want to eliminate the duplicates...
3
by: ryan.paquette | last post by:
In the table there are 2 fields in which I wish to limit (i.e. No Duplicates) Although I do not want to limit them to "No Duplicates" separately. I need them to be limited to "No Duplicates" as...
3
by: Lester | last post by:
I'm driving myself crazy with a problem in trying to translate a query written for Access to that for SQL server. I would think that I would use a trigger, but am not sure how to set it up. We...
1
by: tskmjk55 | last post by:
Recently, I have a requirement to develop a vb.net application wherein the input excel sheet data which has an average of 5000 records should be checked for Internal duplicates (duplicates within the...
3
Thekid
by: Thekid | last post by:
I'm trying to figure out a way to find if there are duplicates in an array. My idea was to take the array as 'a' and make a second array as 'b' and remove the duplicates from 'b' using 'set' and then...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.