Lasso Soft Inc. > Home

[lp_array_join]

Linklp_array_join
AuthorBil Corry
CategoryArray
Version8.x
LicensePublic Domain
Posted02 Dec 2005
Updated02 Dec 2005
More by this author...

Description

Joins an array, similar to array->join, but with additional options.

Sample Usage

var:'test' = (array: 'a','b','c','d','e');

lp_array_join: $test, ', ', -front='"', -back='"', -last=' and ';

var:'in' = (lp_array_join: (: 'abc','def','ghi'), "','",-front="('", -back="')");
var:'sql' = "select * from table where mycol in " $in;
'
'; $sql; Returns: "a, b, c, d and e" select * from table where mycol in ('abc','def','ghi')

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.

[

define_tag:'lp_array_join',
	-description='Similar to array->join, but with more options.',
	-required='array',-copy,
	-optional='join',
	-optional='front',
	-optional='back',
	-optional='first',
	-optional='last';

	if: #array->type != 'array';
		#array = (array: #array);
	/if;
	if: !local_defined:'join';
		local:'join' = '';
	/if;
	if: !local_defined:'front';
		local:'front' = '';
	/if;
	if: !local_defined:'back';
		local:'back' = '';
	/if;
	if: !local_defined:'first';
		local:'first' = #join;
	/if;
	if: !local_defined:'last';
		local:'last' = #join;
	/if;

	if: #array->size == 0;
		return: null;
	/if;

	if: #array->size == 1;
		return: #front (#array->(get: 1)) #back;
	/if;

	if: #array->size == 2;
		if: #last->size;
			return: #front (#array->(join: #last)) #back;
		else: #first->size;
			return: #front (#array->(join: #first)) #back;
		else;
			return: #front (#array->(join: #join)) #back;
		/if;
	/if;

	local:'firstone' = (#array->(get: 1));
	#array->(remove: 1);
	local:'lastone' = (#array->(get: #array->size));
	#array->(remove: #array->size);
	
	return: #front #firstone #first (#array->(join: #join)) #last #lastone #back;

/define_tag;


]

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft