[lp_array_join]

Description

Link: [lp_array_join]
Author: Bil Corry
Category: Array
Version: 8.x
License: Public Domain
Posted: Dec. 02, 2005
Updated: Dec. 02, 2005
More by this author...
Joins an array, similar to array->join, but with additional options.

Parameters

-array array, required An array of elements.
-join string, optional String between each element, default is empty string.
-front string, optional String to prepend to joined string, default is empty string.
-back string, optional String to append to joined string, default is empty string.
-first string, optional String between first and second element, default is -join param.
-last string, optional String between second-to-last and last element, default is -join param.

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;
'<br>';
$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.
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[

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

none

Email:


Password:



Newest

Most Popular