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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eliminating Duplicate Words in a Phrase

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
CA
I am trying to eliminate duplicate words in a phrase. For example:

Before: Microsoft Word Step By Step
After: Microsoft Word Step By

Any suggestions?
Khurram
 
HI Khurram,

You got me curious so I had to do it.
Code:
<CFSet LX=0>
<CFSET X=1>
<CFSET OFFset=1>
<CFSET Limit=3>

<CFSET RemoveFrom=&quot; this sentence repeats this sentence repeats&quot;>

<CFSET Limit = #ListLen(RemoveFrom,&quot; &quot;)# >

<CFLOOP Condition = &quot; X LTE Limit &quot;>
  <CFSET LX = #Listgetat(RemoveFrom,X,&quot; &quot;)# >
  <CFSET Offset= #Find(LX,RemoveFrom,1)#>
  <CFLOOP Condition = &quot; Offset Is not 0 &quot;>
    <CFSET Offset= #Find(LX,RemoveFrom,Offset+Len(LX)-1)#>
    <CFIF Offset IS Not 0>
      <CFSET RemoveFrom = #RemoveChars(RemoveFrom,Offset,Len(LX))#> 
      <CFIF X GT 1><CFSET X = #X# -1></CFIF>
    </CFIF>
  </CFLOOP>
  <CFSET Limit = #ListLen(RemoveFrom,&quot; &quot;)# > 
  <CFSET X = #X#+1>
</CFLOOP>

<CFOUTPUT> RemoveFrom# </CFOUTPUT>
[code]
Hope it helps.  I'm going to have to file this one under silly scripts, I'm sure I'll need it some day.  :)

Have Fun.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top