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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson