CFLib.org – Common Function Library Project

singleLine(s)

Last updated December 13, 2010

author

James Moberg

Version: 0 | Requires: CF5 | Library: StrLib

Description:
Strips Tab, Line Feed, Form Feed, Carriage Return, and non-breaking space (ASCII 160) from strings. Reduces all space characters to a single occurrence.

Return Values:
Returns a string.

Example:

<cfset Test = "a#chr(10)#
b#chr(10)##chr(12)#
#CHR(9)##CHR(9)##CHR(9)#c#chr(13)#
#chr(32)##chr(32)##chr(32)##chr(32)##chr(32)#d#chr(13)#
#chr(160)##chr(160)##chr(160)##chr(160)##chr(160)#e">

<cfoutput>
multi-line<br>
<textarea>#Test#</textarea><br>
single line<br>
<textarea>#singleLine(test)#</textarea>
</cfoutput>

Parameters:

Name Description Required
s String to modify. Yes

Full UDF Source:

/**
 * Strips characters that cause line wrap when exporting.
 * 
 * @param s 	 String to modify. (Required)
 * @return Returns a string. 
 * @author James Moberg (james@ssmedia.com) 
 * @version 0, December 13, 2010 
 */
function singleLine(s){
	s = replacelist(s, "#chr(9)#,#chr(10)#,#chr(12)#,#chr(13)#,#chr(160)#", " , , , , ");
	return trim(reReplace(s, "[[:space:]]{2,}", " ", "all"));
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson