Difference between revisions of "StringTruncate"
Jump to navigation
Jump to search
m (whitespace is your friend, all worship the ellipsis character :p) |
m (<lsl> tag to <source>) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
'''Function''' | '''Function''' | ||
< | <source lang="lsl2"> | ||
string StringTruncate(string text, integer length) { | string StringTruncate(string text, integer length) | ||
if (length < llStringLength(text)) | { | ||
return llGetSubString(text,0, length - 2) + "…"; | if (length < llStringLength(text)) | ||
return llGetSubString(text, 0, length - 2) + "…"; | |||
// else | |||
return text; | return text; | ||
} | } | ||
</ | </source> | ||
'''Example''' | '''Example''' | ||
< | <source lang="lsl2"> | ||
string StringTruncate(string text, integer length) { | string StringTruncate(string text, integer length) | ||
if (length < llStringLength(text)) | { | ||
return llGetSubString(text,0, length - 2) + "…"; | if (length < llStringLength(text)) | ||
return llGetSubString(text, 0, length - 2) + "…"; | |||
// else | |||
return text; | return text; | ||
} | } | ||
default | default | ||
{ | { | ||
state_entry() | state_entry() | ||
{ | { | ||
// llSay( | // llSay(PUBLIC_CHANNEL, "Hello, Avatar!"); | ||
} | } | ||
touch_start(integer | touch_start(integer num_detected) | ||
{ | { | ||
llSay( | llSay(PUBLIC_CHANNEL, StringTruncate("my name Ulrik Ulrik", 11)); | ||
} | } | ||
} | } | ||
</ | </source> | ||
{{LSLC|User-Defined Functions}} | {{LSLC|User-Defined Functions}} |
Latest revision as of 14:38, 22 January 2015
Not to be confused with llStringTrim.
this function will trim a string if it is too long.
Function
string StringTruncate(string text, integer length)
{
if (length < llStringLength(text))
return llGetSubString(text, 0, length - 2) + "…";
// else
return text;
}
Example
string StringTruncate(string text, integer length)
{
if (length < llStringLength(text))
return llGetSubString(text, 0, length - 2) + "…";
// else
return text;
}
default
{
state_entry()
{
// llSay(PUBLIC_CHANNEL, "Hello, Avatar!");
}
touch_start(integer num_detected)
{
llSay(PUBLIC_CHANNEL, StringTruncate("my name Ulrik Ulrik", 11));
}
}