Difference between revisions of "LlStringTrim"
Jump to navigation
Jump to search
m |
(Undo revision 30041 by Revolution Perenti That example is better for notecard reading then how to use llStringTrim, it's overkill) |
||
Line 12: | Line 12: | ||
|caveats | |caveats | ||
|constants= | |constants= | ||
{{{!}}{{Prettytable}} | {{{!}} class="sortable" {{Prettytable}} | ||
{{!}}-{{Hl2}} | {{!}}-{{Hl2}} | ||
! | !{{!}}Constant | ||
!Description | ! title="Value" {{!}} | ||
! Description | |||
{{!}}- | {{!}}- | ||
{{!}} | {{!}}{{LSL Const|STRING_TRIM_HEAD|integer|1|hex=0x1|c=Trims spaces off the beginning.}} | ||
{{!}}{{ | {{!}}{{#var:value}} | ||
{{!}} | {{!}}{{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}} | {{!}}{{LSL Const|STRING_TRIM_TAIL|integer|2|hex=0x2|c=Trims spaces off the end.}} | ||
{{!}}{{ | {{!}}{{#var:value}} | ||
{{!}} | {{!}}{{#var:comment}} | ||
{{!}}- | {{!}}- | ||
{{!}} | {{!}}{{LSL Const|STRING_TRIM|integer|3|hex=0x3|c=Trims spaces off the beginning and end.}} | ||
{{!}}{{ | {{!}}{{#var:value}} | ||
{{!}} | {{!}}{{#var:comment}} | ||
{{!}}} | {{!}}} | ||
|examples= | |examples= | ||
Returns the number of leading and trailing spaces on a string (not particularly useful but shows how to use the function). | |||
string | <pre> | ||
default | default | ||
{ | { | ||
state_entry() | |||
{ | |||
llListen(4, "", llGetOwner(), ""); | |||
} | |||
on_rez(integer a) | |||
{ | { | ||
llResetScript(); | llResetScript(); | ||
} | } | ||
listen(integer chan, string name, key id, string msg) | |||
{ | { | ||
//test for and remove wrapping single or double quotes | |||
if(~llSubStringIndex("'\"", llGetSubString(msg,0,0))) | |||
if(llGetSubString(msg,-1,-1) == llGetSubString(msg,0,0)) | |||
msg = llDeleteSubString(msg, -1, 0); | |||
//track the length | |||
integer length = llStringLength(msg); | |||
//trim msg (not necessary to store these to variables but makes reading easier) | |||
string trim_left = llStringTrim(src, STRING_TRIM_HEAD); | |||
string trim_right = llStringTrim(src, STRING_TRIM_HEAD); | |||
string trim = llStringTrim(src, STRING_TRIM); | |||
//output the results | |||
llOwnerSay("Initial length = " + (string)length; | |||
"\nLeading Spaces = " + (string)(length - llStringLength(trim_left))+ | |||
"\nTrailing Spaces = " + (string)(length - llStringLength(trim_right))+ | |||
"\nTrimmed Message = \"" + trim + "\""); | |||
} | } | ||
} | } | ||
</pre> | </pre> | ||
|helpers | |helpers | ||
|also_functions | |also_functions | ||
Line 95: | Line 71: | ||
|also_events | |also_events | ||
|also_articles | |also_articles | ||
| | |history | ||
*Introduced in 1.13.4 onwards... | |||
|notes= | |||
The following examples will make the same result. | The following examples will make the same result. | ||
<pre> | <pre> | ||
string src = " | string src = " Duh "; | ||
st = llStringTrim(src, STRING_TRIM_HEAD); | st = llStringTrim(src, STRING_TRIM_HEAD); | ||
st = llStringTrim(st , STRING_TRIM_TAIL); | st = llStringTrim(st , STRING_TRIM_TAIL); | ||
</pre> | </pre> | ||
<pre> | <pre> | ||
string src = " | string src = " Duh "; | ||
st = llStringTrim(src, STRING_TRIM); | st = llStringTrim(src, STRING_TRIM); | ||
</pre> | </pre> |
Revision as of 11:14, 1 September 2007
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: string llStringTrim( string src, integer type );330 | Function ID |
0.0 | Forced Delay |
10.0 | Energy |
Returns a string that is src with leading and/or trailing white space (spaces, tabs, and line feeds) trimmed from it.
• string | src | |||
• integer | type | – | STRING_TRIM* flag(s) |
Constant | Description | |
---|---|---|
STRING_TRIM_HEAD | 0x1 | Trims spaces off the beginning. |
STRING_TRIM_TAIL | 0x2 | Trims spaces off the end. |
STRING_TRIM | 0x3 | Trims spaces off the beginning and end. |
Caveats
Examples
Returns the number of leading and trailing spaces on a string (not particularly useful but shows how to use the function).
default { state_entry() { llListen(4, "", llGetOwner(), ""); } on_rez(integer a) { llResetScript(); } listen(integer chan, string name, key id, string msg) { //test for and remove wrapping single or double quotes if(~llSubStringIndex("'\"", llGetSubString(msg,0,0))) if(llGetSubString(msg,-1,-1) == llGetSubString(msg,0,0)) msg = llDeleteSubString(msg, -1, 0); //track the length integer length = llStringLength(msg); //trim msg (not necessary to store these to variables but makes reading easier) string trim_left = llStringTrim(src, STRING_TRIM_HEAD); string trim_right = llStringTrim(src, STRING_TRIM_HEAD); string trim = llStringTrim(src, STRING_TRIM); //output the results llOwnerSay("Initial length = " + (string)length; "\nLeading Spaces = " + (string)(length - llStringLength(trim_left))+ "\nTrailing Spaces = " + (string)(length - llStringLength(trim_right))+ "\nTrimmed Message = \"" + trim + "\""); } }
Notes
The following examples will make the same result.
string src = " Duh "; st = llStringTrim(src, STRING_TRIM_HEAD); st = llStringTrim(st , STRING_TRIM_TAIL);
string src = " Duh "; st = llStringTrim(src, STRING_TRIM);
This is because (STRING_TRIM_HEAD | STRING_TRIM_TAIL) == STRING_TRIM
.