ColdFusion trim()

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

ColdFusion trim()

Post by shiznatix »

I have a string in coldfusion that has several lines. some of the lines are only tabs or blank spaces. I want to remove any line that does not have some text in it. Anybody know how to go about doing this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

From quick searching it appears there is a Trim() method.

http://livedocs.adobe.com/coldfusion/6/ ... pt2109.htm
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

aye yes but my problem is removing the blank lines, maybe my topic title was a little misleading. like in php i would do this:

Code: Select all

$Arr = explode("\n", $Text);
$Clean = array();

foreach ($Arr as $val)
{
    $val = trim($val);

    if ('' != $val)
    {
        $Clean[] = $val;
    }
}

$Text = implode("\n", $Clean);
How would I do this in coldfusion?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Sounds like the best idea. Here is what I tried to no avail:

Code: Select all

<cfset works = REReplace(#works#, "^[a-z0-9A-Z]", "", "ALL")>
i dont believe this warrants a new thread in the Regex forum but if it does lemme know.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is ^,$ line anchors or the entire string's anchors?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

feyd wrote:Is ^,$ line anchors or the entire string's anchors?
I dont follow you but I believe if I showed you an example of the text im dealing with we might be able to figure this out.

Code: Select all

!TRNS	TRNSID	TRNSTYPE	DATE	ACCNT	NAME	AMOUNT	DOCNUM	TOPRINT	ADDR1	ADDR2	ADDR3	ADDR4	ADDR5	SADDR1	SADDR2	SADDR3	SADDR4	SADDR5
!SPL	SPLID	TRNSTYPE	ACCNT	AMOUNT	DOCNUM	MEMO	PRICE	QNTY	INVITEM									
!ENDTRNS																																									
						
					
					
					
					
					
					
                    
TRNS	?	INVOICE	?	Accounts Receivable	Woodward Pharmacy	  549.60	?	Y	Gathagan Investment Co	David Deininger	29 South Second Street	Clearfield, PA 16830	?	Woodward Pharmacy	565 Springstreet	Houtzdale, PA 16651	?	?			

					
			
		
SPL	1	INVOICE	?	  -549.60	?	Week of 01/21/2007 - 01/27/2007	68.70	8	Staffing Hours
notice the completly blank lines? they still contain tabs and spaces but no text. I want to remove those lines.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For example, if you ran REFind() using "^[[:space:]]$"

Does it find anything?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

feyd wrote:For example, if you ran REFind() using "^[[:space:]]$"

Does it find anything?
nothing.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Then I'll have to assume that the anchors are string end markers.

How about...

Code: Select all

\n(?:[[:space:]]*\n)+
or something similar?
Post Reply