StringTruncate

From Second Life Wiki
(Redirected from User:Ugleh Ulrik/trimstring)
Jump to navigation Jump to search

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));
    }
}