Difference between revisions of "StringTruncate"
Jump to navigation
Jump to search
Ugleh Ulrik (talk | contribs) m (moved Truncate to StringTruncate: -.- Forgot to put string in the title) |
Ugleh Ulrik (talk | contribs) (renamed function to StringTruncate) |
||
Line 6: | Line 6: | ||
'''Function''' | '''Function''' | ||
<lsl> | <lsl> | ||
string | string StringTruncate(string text, integer length) { | ||
if (length < llStringLength(text)){ | if (length < llStringLength(text)){ | ||
length = length-1; | length = length-1; | ||
Line 19: | Line 19: | ||
'''Example''' | '''Example''' | ||
<lsl> | <lsl> | ||
string | string StringTruncate(string text, integer length) { | ||
if (length < llStringLength(text)){ | if (length < llStringLength(text)){ | ||
length = length-1; | length = length-1; | ||
Line 38: | Line 38: | ||
touch_start(integer total_number) | touch_start(integer total_number) | ||
{ | { | ||
llSay(0, | llSay(0,StringTruncate("my name Ulrik Ulrik",11)); | ||
} | } | ||
} | } | ||
</lsl> | </lsl> | ||
{{LSLC|User-Defined Functions}} | {{LSLC|User-Defined Functions}} |
Revision as of 14:35, 30 May 2010
Not to be confused with LlStringTrim.
this function will trim a string if it is too long.
Function
<lsl>
string StringTruncate(string text, integer length) {
if (length < llStringLength(text)){ length = length-1; string newstring = llGetSubString(text,0, length) + "..."; return newstring;
}else{
return text;
} } </lsl>
Example <lsl> string StringTruncate(string text, integer length) {
if (length < llStringLength(text)){ length = length-1; string newstring = llGetSubString(text,0, length) + "..."; return newstring;
}else{
return text;
} }
default {
state_entry() { // llSay(0, "Hello, Avatar!"); }
touch_start(integer total_number) { llSay(0,StringTruncate("my name Ulrik Ulrik",11)); }
} </lsl>