|Subject:||Re: How to remove duplicate words from text|
|Posted by:||Richard Cornford (Richa…@litotes.demon.co.uk)|
|Date:||Tue, 22 Jul 2003|
"Voetleuce en fênsievry" <carlit…@websurfer.co.za> wrote in message
> remove duplicate words from a piece of text. This text would
> presumably be pasted into a text box.
> I have, for example, a list of town names, but there are hundreds of
> duplicates, like:
> "Aberdeen Aberdeen Aberdeen Edinburg Edinburg Inverness etc."
> Can you direct me to a script (or write one, please) that will remove
> the excess names and leave just one instance of each name, like:
> "Aberdeen Edinburg Inverness etc."
You need to be clearer about the nature of your list. How does a
space-separated list of city/town names cope with 'Chipping Sudbury' or
'Milton Kenes'. Having decided how the list is going to distinguish one
distinct place name from the next (comma separated?) you could use the
String.split method to produce an array of strings - var placeNameArray
= listText.split( [ delimiter string or regular expression] ); - and
then create a new Object and assign a new (maybe boolean true) property
to the Object using each place name from the array as the property name.
Duplicates would only server to re-set an existing property. Then a -
for(var propName in Obj) loop would enumerate the created properties of
the object and could be used to create a duplicate-free list.
How to remove duplicate words from text posted by carlit…@websurfer.co.za (Voetleuce en fênsievry) on 22 Jul 2003