[pk_stringtointeger]

Description

Link: [pk_stringtointeger]
Author: Pier Kuipers
Category: String
Version: 8.x
License: Public Domain
Posted: Jan. 10, 2006
Updated: Jan. 28, 2007
More by this author...
Tag converts a formatted number such as $100,000 back to an integer (e.g. 100000).
Note the difference with Bil's tag [lp_string_getNumeric] - my tag returns the integer value, ignoring digits after a period:
[pk_stringtointeger] $100,000.45 -> 100000 [lp_string_getNumeric] $100,000.45 -> 10000045

Parameters

none


Sample Usage

[pk_stringtointeger:'$100,000.45']
-> 100000

[pk_stringtointeger:'+1-234 yada 23-65/01']
-> 1234236501

[pk_stringtointeger:'+1-234 yada. 23-65/01']
-> 1234
						

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?LassoScript

	If: !(lasso_tagexists:'pk_stringtointeger');
	
		define_tag:'pk_stringtointeger',
			-required='mystring';

			#mystring = (string:#mystring);
			local:'splitString'=(#mystring -> split:'');
			local:'newinteger'=string;

			Iterate:#splitString, local:'x';

				If:(#x -> isdigit);
					#newinteger += #x;
				Else:(#x == '.');
					loop_abort;
				/If;

			/Iterate;

			return:(integer:#newinteger);

		/define_tag;
		
	/If;	

?>

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net