CFLib.org – Common Function Library Project

parseInt(string)

Last updated May 22, 2003

author

Marco G. Williams

Version: 1 | Requires: CF5 | Library: StrLib

Description:
This UDF will only grab the first Numbers in a string. If you have a string " mozilla/ 4.0 (winNT; IE5.0)" It will return 4.0 and ignore all the rest of your string.

Return Values:
Returns a string.

Example:

<CFOUTPUT>
#parseInt("Opera/7.03 (Windows NT 5.0; U) [en]")#
</CFOUTPUT>

Returns: 7.03

Parameters:

Name Description Required
string String to parse. Yes

Full UDF Source:

/**
 * Parse out the first set of numbers in a string.
 * 
 * @param string 	 String to parse. (Required)
 * @return Returns a string. 
 * @author Marco G. Williams (email@marcogwilliams.com) 
 * @version 1, May 22, 2003 
 */
function parseInt(String){
	var NewString = "";
	var i = 1;

	for(i=1; i lt Len(String); i = i + 1) {
		if( isNumeric( mid(String,i,1) ) ) { newString = val( mid( String,i,Len(String) ) ); break;}
	}
	return NewString;
}
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