WrapText

De DigiWiki.

Example:

string myWrappedText = WrapText(Title, 25);

Specification:

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");
}
Outils personnels
  • Cette page a été consultée 464 fois.
donate
Google Ads