rereplace for removing repeating characters

2010-11-02 Thread Richard White

Hi, i need to replace all repeating commas in a string with only one comma, 
plus remove the trailing comma, have tried a few different routes 
unsuccessfully and would appreciate any input:

for example i would the the string: 'Genns,,DrBish Stratford,,,' 
to become: 'Genns,Dr,Bish Stratford'

thanks


~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:338747
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: rereplace for removing repeating characters

2010-11-02 Thread David McGraw

I am sure there are some nice slick regular expressions to do this, but I
just simply do this a very dumbed down way.

cfset myVar = ReplaceNoCase(myVar , ,, ,, ALL)
cfset myVar = ReplaceNoCase(myVar , , ,, ALL)
cfset myVar = ReplaceNoCase(myVar ,  ,, ALL)
cfset myVar = ReplaceNoCase(myVar , ,,, ,, ALL)

You could also write a loop to run until FindNoCase(myVar, ,,) EQ FALSE,
so you keep turning double commas, into single commas which will continue to
reduce the commas, until there are no matches.

Again, there is probably a RegEx way to do this, but I don't know RegEx off
the top of my head.

Regards,
David McGraw
Oyova Software, LLC
http://www.oyova.com


On Tue, Nov 2, 2010 at 8:34 AM, Richard White rich...@j7is.co.uk wrote:


 Hi, i need to replace all repeating commas in a string with only one comma,
 plus remove the trailing comma, have tried a few different routes
 unsuccessfully and would appreciate any input:

 for example i would the the string: 'Genns,,DrBish Stratford,,,'
 to become: 'Genns,Dr,Bish Stratford'

 thanks


 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:338748
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: rereplace for removing repeating characters

2010-11-02 Thread Richard White

thanks for the reply, i actually just found a shortcut! i converted the string 
to an array which removed any empty array elements, and then converted back to 
a list and therefore deleted all the duplicate, and trailing commas

 

I am sure there are some nice slick regular expressions to do this, but I
just simply do this a very dumbed down way.

cfset myVar = ReplaceNoCase(myVar , ,, ,, ALL)
cfset myVar = ReplaceNoCase(myVar , , ,, ALL)
cfset myVar = ReplaceNoCase(myVar ,  ,, ALL)
cfset myVar = ReplaceNoCase(myVar , ,,, ,, ALL)

You could also write a loop to run until FindNoCase(myVar, ,,) EQ FALSE,
so you keep turning double commas, into single commas which will continue to
reduce the commas, until there are no matches.

Again, there is probably a RegEx way to do this, but I don't know RegEx off
the top of my head.

Regards,
David McGraw
Oyova Software, LLC
http://www.oyova.com




 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:338750
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm


Re: rereplace for removing repeating characters

2010-11-02 Thread Azadi Saryev

try this:
cfset string = rereplace(rereplace(string, ,+$, ), ,+, ,, all)

Azadi

On 02/11/2010 20:34 , Richard White wrote:
 Hi, i need to replace all repeating commas in a string with only one comma, 
 plus remove the trailing comma, have tried a few different routes 
 unsuccessfully and would appreciate any input:

 for example i would the the string: 'Genns,,DrBish Stratford,,,'
 to become: 'Genns,Dr,Bish Stratford'

 thanks


 

~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:338751
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm