Simple trim() Function

Note: There is now a native LSL function for trimming strings called llStringTrim(), you should use it instead. This is being kept for archival purposes only.

This is a simple function for trimming leading and trailing spaces from a string, useful when parsing configuration from a notecard (at least that’s where I use it).

  1. string trim(string source) // TRIMS ALL LEADING AND TRAILING SPACES FROM A STRING{
  2.  
  3. while (llGetSubString(source, 0, 0) == " " && llStringLength(source) > 0)
  4.  
  5. {
  6.  
  7. source = llDeleteSubString(source, 0, 0);
  8.  
  9. }
  10.  
  11. while (llGetSubString(source, -1-1) == " ")
  12.  
  13. {
  14.  
  15. source = llDeleteSubString(source, -1, -1);
  16.  
  17. }
  18.  
  19. return source;
  20.  
  21. }

Leave a Reply