Page 1 of 1
ColdFusion trim()
Posted: Thu Mar 01, 2007 3:38 pm
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?
Posted: Thu Mar 01, 2007 4:36 pm
by feyd
From quick searching it appears there is a Trim() method.
http://livedocs.adobe.com/coldfusion/6/ ... pt2109.htm
Posted: Fri Mar 02, 2007 8:41 am
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?
Posted: Fri Mar 02, 2007 8:42 am
by feyd
Posted: Fri Mar 02, 2007 8:51 am
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.
Posted: Fri Mar 02, 2007 9:13 am
by feyd
Is ^,$ line anchors or the entire string's anchors?
Posted: Fri Mar 02, 2007 9:26 am
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.
Posted: Fri Mar 02, 2007 9:32 am
by feyd
For example, if you ran REFind() using "^[[:space:]]$"
Does it find anything?
Posted: Fri Mar 02, 2007 11:37 am
by shiznatix
feyd wrote:For example, if you ran REFind() using "^[[:space:]]$"
Does it find anything?
nothing.
Posted: Fri Mar 02, 2007 1:30 pm
by feyd
Then I'll have to assume that the anchors are string end markers.
How about...
or something similar?