CFLib.org – Common Function Library Project

CountLines(text)

Last updated June 3, 2003

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 0 time(s). Average Rating: 0

Description:
This function returns the number of lines in a text file loaded into a string. For this UDF, a line is defined as a string ending with Chr(13) or Chr(10). As a reminder, note that list functions only take single character delimiters. When you pass N characters as the delimiter, list functions will use any of the characters as the delimiter.

Return Values:
Returns a number.

Example:

view plain print about
<cfsavecontent variable="foo">
This is Foo.
This is not foo.
Who cares about foo?
</cfsavecontent>

<cfoutput>#CountLines(foo)#</cfoutput>

Parameters:

Name Description Required
text String to parse. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * This function returns the number of lines in a text file.
 * 
 * @param text      String to parse. (Required)
 * @return Returns a number. 
 * @author Matheus Antonelli (matheus_antonelli@ig.com.br) 
 * @version 1, June 3, 2003 
 */

function CountLines(text) {
  var CRLF = Chr(13) & Chr(10);
  return ListLen(text,CRLF);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson