Difference between revisions of "StringTruncate"

From Second Life Wiki
Jump to navigation Jump to search
(renamed function to StringTruncate)
m (whitespace is your friend, all worship the ellipsis character :p)
Line 1: Line 1:
Not to be confused with [[LlStringTrim]].
Not to be confused with [[llStringTrim]].


this function will trim a string if it is too long.
this function will trim a string if it is too long.


'''Function'''
'''Function'''
Line 8: Line 7:
string StringTruncate(string text, integer length) {
string StringTruncate(string text, integer length) {
     if (length < llStringLength(text)){
     if (length < llStringLength(text)){
    length = length-1;
        return llGetSubString(text,0, length - 2) + "";
    string newstring = llGetSubString(text,0, length) + "...";
     }else{
     return newstring;
        return text;
}else{
    }
    return text;
}
}
}
</lsl>
</lsl>
Line 21: Line 18:
string StringTruncate(string text, integer length) {
string StringTruncate(string text, integer length) {
     if (length < llStringLength(text)){
     if (length < llStringLength(text)){
    length = length-1;
        return llGetSubString(text,0, length - 2) + "";
    string newstring = llGetSubString(text,0, length) + "...";
     } else {
     return newstring;
        return text;
}else{
    }
    return text;
}
}
}



Revision as of 22:34, 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)){
       return llGetSubString(text,0, length - 2) + "…";
   }else{
       return text;
   }

} </lsl>

Example <lsl> string StringTruncate(string text, integer length) {

   if (length < llStringLength(text)){
       return llGetSubString(text,0, length - 2) + "…";
   } else {
       return text;
   }

}

default {

   state_entry()
   {
      // llSay(0, "Hello, Avatar!");
   }
   touch_start(integer total_number)
   {
       llSay(0,StringTruncate("my name Ulrik Ulrik",11));
   }

} </lsl>