[lp_string_chr]

Description

Link: [lp_string_chr]
Author: Bil Corry
Category: String
Version: 8.x
License: Public Domain
Posted: Jan. 17, 2006
Updated: Dec. 03, 2007
More by this author...

Returns a character given an integer octet or an array of integer octets.

Requires [lp_math_decToOctet], [lp_math_hexToDec]

Parameters

-bytes integer, required An integer octet to convert to a character. Optionally may pass it as an array of integer octets.
-character_set string, optional The character set to use for encoding. Default is to use the outgoing encoding.
-hex boolean, optional Optionally allows passing hex values instead of decimal values.

Sample Usage

For UTF-8:

[lp_string_chr: (lp_math_hextodec: 'C2A9')]<br>
[lp_string_chr: 84] returns 'T'<br>
[lp_string_chr: (array: 195, 164)] returns ä (a with umlaut)<br>
[lp_string_chr: 50084] returns ä (a with umlaut)<br>
[lp_string_chr: (array: 226,130,172)] returns euro symbol<br>
						

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
[

define_tag:'lp_string_chr',
	-description='Returns a character given an integer octet or an array of integer octets.',
	-priority='replace',
	-required='bytes', -copy,
	-optional='character_set',
	-optional='hex';

// http://www.unicode.org/charts/
// http://www.426.ch/ascii.html

	if: (local_defined:'hex');
		#bytes = (array: (lp_math_hexToDec:(string: #bytes)));
	/if;

	if: #bytes->type != 'array';	
		#bytes = (array: (integer: #bytes));
	/if;
	
	if: !(local_defined:'character_set');
		local:'character_set' = $__encoding__;
	/if;

	local:'return' = bytes;
	iterate: (lp_math_decToOctet: #bytes), local:'octet';
		#return->(import8bits: #octet);
	/iterate;
	
	return: #return->(exportstring: #character_set);

/define_tag;

]

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular