Difference between revisions of "WrapText"
Jump to navigation
Jump to search
Ugleh Ulrik (talk | contribs) |
Ugleh Ulrik (talk | contribs) |
||
Line 37: | Line 37: | ||
{{LSLC|Examples|WrapText|}} | {{LSLC|Examples|WrapText|}} | ||
{{LSLC| | {{LSLC|User-Defined Functions}} |
Revision as of 13:52, 25 May 2010
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Function: string WrapText(string source, integer length);
Splits a long text string into lines whose character length you get to specify. Useful, for instance, for long floating text to make it tidier. It will not split words at odd places but instead look for the space in the text nearest to the length you have specified.
Example: string myWrappedText = WrapText(Title, 25);
Specification
<lsl>string WrapText(string pcText, integer piWidth) {
list laLines = []; integer liIndex; integer liKeep; // Specifies if we keep the char pointed at or not integer liLen = llStringLength(pcText); list llSearch = [" ", "\n"]; while (liLen > 0) { liIndex = piWidth; if (!(liKeep = (liLen <= piWidth))) { while ((liIndex >= 0) && (-1 == llListFindList(llSearch, (list)llGetSubString(pcText, liIndex, liIndex)))) --liIndex; if (liIndex <= 0) { liIndex = piWidth; liKeep = 1; } } laLines += llGetSubString(pcText, 0, liIndex - 1); pcText = llDeleteSubString(pcText, 0, liIndex - liKeep); liLen -= (1 + liIndex - liKeep); } return llDumpList2String(laLines,"\n");
}</lsl>