Skip to main content
Known Participant
January 22, 2010
Question

how to remove spaces

  • January 22, 2010
  • 2 replies
  • 718 views

Assignee: cf_supp Status: Open, In Progress, Reopened, Test Deployment Pending, Production Deployment Pending, Ready for QA, Bus Analysis, Ready for Development and Deployment Complete Sorted by: Created descending, then Key descending

the above is the paragraph that i am displaying in table from query but i am not able to remove spaces in between , i tried with trim and also with replace functions.

Any help in this

Thanks in advance

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
January 23, 2010
the above is the paragraph that i am displaying in table from query but
i am not able to remove spaces in between , i tried with trim and also
with replace functions.

There's always the old trick of continually applying a replacement function until you're done. It just might be of help here. I assume you will want to stop when there is only a single space between the words.

<!--- variable to simulate a paragraph containing arbitrary space characters --->

<cfsavecontent variable="paragraph">
Assignee: cf_supp Status: Open, In Progress,
           Reopened,             Test Deployment Pending,   Production
            Deployment Pending,    Ready for QA, Bus
     Analysis, Ready for Development and Deployment
Complete Sorted by: Created descending,              then Key descending
</cfsavecontent>

<p>
<strong>Paragraph before:</strong>
<pre><cfoutput>#paragraph#</cfoutput></pre>
</p>

<!--- Replace whitespace characters like linefeed, carriage-return, tab, space, etc., with a single space --->
<cfset paragraph = REreplace(paragraph,"[[:space:]]", " ", "all")>
<cfloop condition="true">
    <cfset old_paragraph = paragraph>   
    <!--- Replace two adjoining spaces with a single space --->
    <cfset paragraph = replace(paragraph,"  ", " ", "all")>
    <!--- Continue till there is no more replacement --->
    <cfif compareNoCase(old_paragraph, paragraph) is 0>
    <cfbreak>
    </cfif>
</cfloop>
   
<p>
<strong>Paragraph after:</strong>
<pre><cfoutput>#paragraph#</cfoutput></pre>
</p>

Inspiring
January 23, 2010

trim() was never the right opyion here as that only removes whitespace from the ends of a string.  But not sure why replace() wouldn't work for you.  Can you post your code (it's always good to post your code if you're saying "my code didn't work", btw).

--

Adam