PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
AngelScript
How-to
Scripts
  • Strings
AngelScriptStrings
November 04, 2025

AngelScript Strings

Original document: https://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_stdlib_string.html

Basic String Methods

  1. uint length // Use without "()"

Returns the length of the string.

  1. void resize(uint)

Sets the length of the string.

  1. bool isEmpty() const

Returns true if the string is empty (length is zero).

  1. string substr(uint start = 0, int count = -1) const

Returns a string with the content starting at start and the number of bytes given by count. The default arguments will return the whole string as the new string.

  1. void insert(uint pos, const string &in other)

Inserts another string other at position pos in the original string.

  1. void erase(uint pos, int count = -1)

Erases a range of characters from the string, starting at position pos and counting count characters.

  1. pos = s.findFirst("letimix"); // find substring
  2. log("pos: "+pos); // pos: 7
  3.  
  4. pos = s.findFirst("e");
  5. log("pos: "+pos); // pos: 3
  6.  
  7. pos = s.findFirst("e", pos+1); // find next "e"
  8. log("pos: "+pos); // pos: 8
  9.  
  10. pos = s.findLast("e");
  11. log("pos: "+pos); // pos: 20
  12.  
  13. pos = s.findLast("e", pos-1); // find previous "e"
  14. log("pos: "+pos); // pos: 8
  15.  
  16. pos = s.findLast("abc"); // not in the string
  17. log("pos: "+pos); // pos: -1
  18.  
  19. pos = s.findFirstOf("slD"); // find any of chars
  20. log("pos: "+pos); // pos: 2 ('s' in Users)
  21.  
  22. pos = s.findFirstOf("slD", pos+1);
  23. log("pos: "+pos); // pos: 5 (next 's' in Users)
  24.  
  25. pos = s.findLastOf("slD");
  26. log("pos: "+pos); // pos: 23 ('s' in Documents)
  27.  
  28. pos = s.findLastOf("slD", pos-1);
  29. log("pos: "+pos); // pos: 15 ('D' in Documents)
  30.  
  31. pos = s.findFirstNotOf("/");
  32. log("pos: "+pos); // pos: 1 ('U' in Users)
  33.  
  34. pos = s.findFirstNotOf("/", pos+1);
  35. log("pos: "+pos); // pos: 2 ('s' in Users)
  36.  
  37. pos = s.findLastNotOf("/");
  38. log("pos: "+pos); // pos: 23 ('s' in Documents)
  39.  
  40. pos = s.findLastNotOf("/", pos-1); // find any of chars
  41. log("pos: "+pos); // pos: 22 ('t' in Documents)

Search Methods

  1. int findFirst(const string &in str, uint start = 0) const

Find the first occurrence of the value str in the string, starting at start. If no occurrence is found a negative value will be returned.

  1. int findLast(const string &in str, int start = -1) const

Find the last occurrence of the value str in the string. If start is informed the search will begin at that position, i.e. any potential occurrence after that position will not be searched. If no occurrence is found a negative value will be returned.

  1. int findFirstOf(const string &in chars, int start = 0) const

Finds the first character in the string that matches one of the characters in chars, starting at start. If no occurrence is found a negative value will be returned.

  1. int findFirstNotOf(const string &in chars, int start = 0) const

Finds the first character that doesn't match any of those in chars.

  1. int findLastOf(const string &in chars, int start = -1) const

Same as findFirstOf but starts the search from the end of the string.

  1. int findLastNotOf(const string &in chars, int start = -1) const

Same as findFirstNotOf but starts the search from the end of the string.

  1. string s = "$_USER_DOCUMENTS_PATH_$";
  2. log(s); // /Users/letimix/Documents
  3.  
  4. int pos;
  5.  
  6. pos = s.findFirst("letimix");
  7. log("pos: "+pos); // pos: 7
  8.  
  9. pos = s.findFirst("e");
  10. log("pos: "+pos); // pos: 3
  11.  
  12. pos = s.findFirst("e", pos+1); // find next "e"
  13. log("pos: "+pos); // pos: 8
  14.  
  15. pos = s.findLast("e");
  16. log("pos: "+pos); // pos: 20
  17.  
  18. pos = s.findLast("e", pos-1); // find previous "e"
  19. log("pos: "+pos); // pos: 8
  20.  
  21. pos = s.findLast("abc"); // not in the string
  22. log("pos: "+pos); // pos: -1
  23.  
  24. pos = s.findFirstOf("slD"); // find any of chars
  25. log("pos: "+pos); // pos: 2 ('s' in Users)
  26.  
  27. pos = s.findFirstOf("slD", pos+1);
  28. log("pos: "+pos); // pos: 5 (next 's' in Users)
  29.  
  30. pos = s.findLastOf("slD");
  31. log("pos: "+pos); // pos: 23 ('s' in Documents)
  32.  
  33. pos = s.findLastOf("slD", pos-1);
  34. log("pos: "+pos); // pos: 15 ('D' in Documents)
  35.  
  36. pos = s.findFirstOf("slD"); // find any of chars
  37. log("pos: "+pos); // pos: 2 ('s' in Users)
  38.  
  39. pos = s.findFirstNotOf("/");
  40. log("pos: "+pos); // pos: 1 ('U' in Users)
  41.  
  42. pos = s.findFirstNotOf("/", pos+1);
  43. log("pos: "+pos); // pos: 2 ('s' in Users)
  44.  
  45. pos = s.findLastNotOf("/");
  46. log("pos: "+pos); // pos: 23 ('s' in Documents)
  47.  
  48. pos = s.findLastNotOf("/", pos-1); // find any of chars
  49. log("pos: "+pos); // pos: 22 ('t' in Documents)

Split and join

  1. array<string>@ split(const string &in delimiter) const

Splits the string in smaller strings where the delimiter is found.

  1. string join(const array<string> &in arr, const string &in delimiter)

Concatenates the strings in the array into a large string, separated by the delimiter.

  1. string s = "$_USER_DOCUMENTS_PATH_$";
  2. log(s); // /Users/letimix/Documents
  3.  
  4. array<string> ar = s.split("/");
  5.  
  6. log("array size: "+ar.length); // 4 (first empty before first /)
  7.  
  8. for(uint i=0;i<ar.length;i++) {
  9. log(ar[i]); // outputs [empty], Users, letimix, Documents
  10. }
  11.  
  12. ar.insertLast("Blue Cat Audio"); // add pieces to array
  13. ar.insertLast("Blue Cat's Plug'n Script");
  14.  
  15. s = join(ar, "/"); // join array back to string
  16.  
  17. log(s); // /Users/letimix/Documents/Blue Cat Audio/Blue Cat's Plug'n Script

Parsing Functions

  1. int64 parseInt(const string &in str, uint base = 10, uint &out byteCount = 0)

Parses the string for an integer value. The base can be 10 or 16 to support decimal numbers or hexadecimal numbers. If byteCount is provided it will be set to the number of bytes that were considered as part of the integer value.

  1. uint64 parseUInt(const string &in str, uint base = 10, uint &out byteCount = 0)

Same as parseInt but for unsigned integers.

  1. double parseFloat(const string &in, uint &out byteCount = 0)

Parses the string for a floating point value. If byteCount is provided it will be set to the number of bytes that were considered as part of the value.

  1. string s;
  2.  
  3. s = "123";
  4. int i;
  5.  
  6. log("--parseInt--");
  7.  
  8. i = parseInt(s);
  9. log("i: "+i); // i: 123
  10.  
  11. uint len;
  12. s = "-123.44 miles";
  13. i = parseInt(s, 10, len);
  14. log("i: "+i + " len: "+len); // i: -123 len: 4
  15.  
  16. s = " 123 number";
  17. i = parseInt(s, 10, len); // can starts only with a number or -,+
  18. log("i: "+i + " len: "+len); // i: 0 len: 0
  19.  
  20. s = "10e2"; // scientific notation works only with parseFloat
  21. i = parseInt(s);
  22. log("i: "+i); // i: 10
  23.  
  24. s = "FF";
  25. i = parseInt(s, 16); // convert hex value
  26. log("i: "+i); // i: 255
  27.  
  28. log("--parseUInt--");
  29.  
  30. uint u;
  31.  
  32. s = "123";
  33. u = parseUInt(s);
  34. log("u: "+u); // u: 123
  35.  
  36. s = "-123";
  37. u = parseUInt(s);
  38. log("u: "+u); // u: 0
  39.  
  40. s = "-123";
  41. u = parseInt(s); // just to test the difference
  42. log("u: "+u); // u: 4294967173
  43.  
  44. s = "FF";
  45. u = parseUInt(s, 16); // convert hex value
  46. log("u: "+u); // u: 255
  47.  
  48. s = "FFCCDD";
  49. u = parseUInt(s, 16, len);
  50. log("u: "+u + " len: "+len); // u: 16764125 len: 6
  51.  
  52. s = "#FFCCDD"; // will fail cause starts with #
  53. u = parseUInt(s, 16, len);
  54. log("u: "+u + " len: "+len); // u: 0 len: 0
  55.  
  56. log("--parseFloat--");
  57.  
  58. double f;
  59.  
  60. s = "123.45678910";
  61. f = parseFloat(s);
  62. log("f: "+formatFloat(f, "", 3, 10)); // f: 123.4567891000
  63.  
  64. s = "-1e4 number"; // scientific notation works here
  65. f = parseFloat(s, len);
  66. log("f: "+f + " len: "+len); // f: -10000 len: 4

Formatting Functions

  1. string formatInt(int64 val, const string &in options = '', uint width = 0)
  2.  
  3. // Blue Cat Audio alternative for DSP thread to convert without memory allocation
  4. void intToString(int64 val, string& s, const string &in options = "", uint width = 0);

Formats an integer value with specified options and width.

  1. string formatUInt(uint64 val, const string &in options = '', uint width = 0)
  2.  
  3. // Blue Cat Audio alternative for DSP thread to convert without memory allocation
  4. void uIntToString(uint64 val, string& s, const string &in options = "", uint width = 0);

Formats an unsigned integer value with specified options and width.

  1. string formatFloat(double val, const string &in options = '', uint width = 0, uint precision = 0)
  2.  
  3. // Blue Cat Audio alternative for DSP thread to convert without memory allocation
  4. void floatToString(double val, string& s, const string &in options = "", uint width = 0, uint precision = 0);

Formats a floating-point value with specified options, width, and precision.

Format Options

Character Description
l left justify
0 pad with zeroes
+ always include the sign, even if positive
space add a space in case of positive number
h hexadecimal integer small letters (not valid for formatFloat)
H hexadecimal integer capital letters (not valid for formatFloat)
e exponent character with small e (only valid for formatFloat)
E exponent character with capital E (only valid for formatFloat)

Examples:

  1. // Left justify number in string with 10 characters
  2. string justified = formatInt(number, 'l', 10);
  3.  
  4. // Create hexadecimal representation with capital letters, right justified
  5. string hex = formatInt(number, 'H', 10);
  6.  
  7. // Right justified, padded with zeroes and two digits after decimal separator
  8. string num = formatFloat(number, '0', 8, 2);

Supporting String Object and Functions

The string object supports a number of operators, and has several class methods and supporting global functions to facilitate the manipulation of strings.

Note: Unless otherwise stated, all methods and functions work on the individual bytes in the string. They do not attempt to understand encoded characters, e.g. UTF-8 encoded characters that can take up to 4 bytes.

Operators

`=` Assignment

  1. string = string

The assignment operator copies the content of the right hand string into the left hand string.
Assignment of primitive types is allowed, which will do a default transformation of the primitive to a string.

`+`, `+=` Concatenation

  1. string + string
  2. string += string

The concatenation operator appends the content of the right hand string to the end of the left hand string.
Concatenation of primitive types is allowed, which will do a default transformation of the primitive to a string.

`==`, `!=` Equality

  1. string == string
  2. string != string

Compares the content of the two strings.

`<`, `>`, `<=`, `>=` Comparison

  1. string < string
  2. string > string
  3. string <= string
  4. string >= string

Compares the content of the two strings. The comparison is done on the byte values in the strings, which may not correspond to alphabetical comparisons for some languages.

`[]` Index Operator

  1. string[index]

The index operator gives access to a single byte in the string.


Comments

Please, authorize to view and post comments.

2020 - 2025 © Site by LetiMix · Donate  |  Plug'n Script and KUIML by Blue Cat Audio