LlStringLength: Difference between revisions

From Second Life Wiki
Jump to navigation Jump to search
added example
Nelson Jenkins (talk | contribs)
Revise incorrect reference to llHTTPResponse being byte-limited (llHTTPResponse has no limit) and clarify section on characters vs. bytes
 
(15 intermediate revisions by 10 users not shown)
Line 4: Line 4:
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=that is the string length of '''str'''.
|return_text=that is the number of characters in '''str'''.
|spec
|spec
|caveats
|caveats=
* The index of the last character is not equal to the string length.
** Character indexes start at zero (the index of the first character is zero).
* [[llStringLength]] returns the number of characters - not bytes - in the string.
** Some functions that accept strings are limited to bytes, not characters.
** LSL-2 uses UTF-8 strings and Mono uses UTF-16; both support multibyte characters.
** To get the number of bytes in a string instead, use the example snippet on [[llStringToBase64]] (there is no native LSL function to do this).
|constants
|constants
|examples=<lsl>
|examples=
default {
<source lang="lsl2">
// assumptions:  
// assumptions:  
//       object name: LSLWiki
//   object name: LSLWiki
//       script name: _lslwiki
//   script name: _lslwiki
      state_entry() {
 
        integer i;
default
{
    state_entry()
    {
         string HowLongAmI = "123";
         string HowLongAmI = "123";
         i = llStringLength(HowLongAmI);
         integer strlen = llStringLength(HowLongAmI);
         llOwnerSay( HowLongAmI + " has " (string) i + " letters.");  
         llOwnerSay( "'" + HowLongAmI + "' has " +(string) strlen + " characters.");
      // The owner of object LSLWiki will hear  
        // The owner of object LSLWiki will hear  
      // LSLWiki: 123 has 3 letters.
        // LSLWiki: '123' has 3 characters.
      }
    }
}
}
</lsl>
 
</source>
 
|helpers
|helpers
|also_functions
|also_functions={{LSL DefineRow||[[llGetListLength]]|}}
|also_events
|also_events
|also_tests
|also_tests

Latest revision as of 13:11, 21 August 2025

Summary

Function: integer llStringLength( string str );
0.0 Forced Delay
10.0 Energy

Returns an integer that is the number of characters in str.

• string str

Caveats

  • The index of the last character is not equal to the string length.
    • Character indexes start at zero (the index of the first character is zero).
  • llStringLength returns the number of characters - not bytes - in the string.
    • Some functions that accept strings are limited to bytes, not characters.
    • LSL-2 uses UTF-8 strings and Mono uses UTF-16; both support multibyte characters.
    • To get the number of bytes in a string instead, use the example snippet on llStringToBase64 (there is no native LSL function to do this).

Examples

// assumptions: 
//    object name: LSLWiki
//    script name: _lslwiki

default
{
    state_entry()
    {
        string HowLongAmI = "123";
        integer strlen = llStringLength(HowLongAmI);
        llOwnerSay( "'" + HowLongAmI + "' has " +(string) strlen + " characters.");
        // The owner of object LSLWiki will hear 
        // LSLWiki: '123' has 3 characters.
    }
}

See Also

Functions

•  llGetListLength

Deep Notes

Signature

function integer llStringLength( string str );