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

AngelScript Strings

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. string s;
  2.  
  3. log("--formatInt and intToString--");
  4.  
  5. s = formatInt(-1000);
  6. log(s); // "-1000"
  7.  
  8. s = formatInt(1000, "", 10);
  9. log(s); // " 1000" // adds spaces
  10.  
  11. s = formatInt(1000, "+l", 10);
  12. log(s); // "+1000 " // adds sign and spaces, aligns left
  13.  
  14. s = formatInt(1000, " l", 10);
  15. log(s); // " 1000 " // same, but adds space instead of +
  16.  
  17. s = formatInt(255, "h");
  18. log(s); // "ff"
  19.  
  20. s = formatInt(255, "0H", 6);
  21. log(s); // "0000FF"
  22.  
  23. intToString(255, s, "0H", 4); // avoids memory allocation
  24. log(s); // "00FF"
  25.  
  26. log("--formatUInt and uIntToString--");
  27.  
  28. s = formatUInt(30, "0", 4);
  29. log(s); // "0030"
  30.  
  31. s = formatUInt(15, "0H", 2); // format two-digit hex
  32. log(s); // "0F"
  33.  
  34. uIntToString(239, s, "0H", 2); // avoids memory allocation
  35. log(s); // "EF"
  36.  
  37. log("--formatFloat and floatToString--");
  38.  
  39. s = formatFloat(123.456789);
  40. log(s); // "123" // cause precision is 0 by default
  41.  
  42. s = formatFloat(1, "0", 5, 2);
  43. log(s); // "01.00"
  44.  
  45. s = formatFloat(123.456789, "", 7, 2);
  46. log(s); // " 123.46"
  47.  
  48. s = formatFloat(123.456789, "+l", 15, 5);
  49. log(s); // "+123.45679 "
  50.  
  51. s = formatFloat(2345.6789, " ", 15, 5);
  52. log(s); // " 2345.67890"
  53.  
  54. s = formatFloat(0.05, "e");
  55. log(s); // "5e-02"
  56.  
  57. floatToString(345.6789, s, "", 3, 2); // avoids memory allocation
  58. log(s); // "345.68"

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.

  1. string s1, s2;
  2.  
  3. s1 = "abc";
  4. s2 = "def";
  5. log(s1 + " > " + s2 + " = " + (s1>s2)); // abc > def = false
  6. log(s1 + " < " + s2 + " = " + (s1<s2)); // abc < def = true
  7.  
  8. s1 = "abc";
  9. s2 = "ab";
  10. log(s1 + " > " + s2 + " = " + (s1>s2)); // abc > ab = true
  11. log(s1 + " < " + s2 + " = " + (s1<s2)); // abc < ab = false
  12.  
  13. s1 = "ABC";
  14. s2 = "abc";
  15. log(s1 + " > " + s2 + " = " + (s1>s2)); // ABC > abc = false
  16. log(s1 + " < " + s2 + " = " + (s1<s2)); // ABC < abc = true
  17.  
  18. s1 = "Abc";
  19. s2 = "aBC";
  20. log(s1 + " > " + s2 + " = " + (s1>s2)); // Abc > aBC = false
  21. log(s1 + " < " + s2 + " = " + (s1<s2)); // Abc < aBC = true
  22.  
  23. s1 = "Abc";
  24. s2 = "ABC";
  25. log(s1 + " > " + s2 + " = " + (s1>s2)); // Abc > ABC = true
  26. log(s1 + " < " + s2 + " = " + (s1<s2)); // Abc < ABC = false
  27.  
  28. s1 = "Abc";
  29. s2 = "ABCDE"; // So length is less important than char byte values
  30. log(s1 + " > " + s2 + " = " + (s1>s2)); // Abc > ABCDE = true
  31. log(s1 + " < " + s2 + " = " + (s1<s2)); // Abc < ABCDE = false
  32.  
  33. s1 = "ABCabc";
  34. s2 = "abc";
  35. log(s1 + " > " + s2 + " = " + (s1>s2)); // ABCabc > abc = false
  36. log(s1 + " < " + s2 + " = " + (s1<s2)); // ABCabc < abc = true
  37.  
  38. s1 = "abcABC";
  39. s2 = "abc"; // but if starting char values equals, then length is counted
  40. log(s1 + " > " + s2 + " = " + (s1>s2)); // abcABC > abc = true
  41. log(s1 + " < " + s2 + " = " + (s1<s2)); // abcABC < abc = false

`[]` Index Operator

  1. string[index]

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

About strings in AngelScript for Plug'n Script

Strings hold an array of bytes. Normally they are used to store text but can really store any kind of binary data.

There are two types of string constants supported in the AngelScript language, the normal quoted string (with normal "), and the documentation strings, called heredoc strings (with triple """), see below.

Single quotation marks (') in PnS/KUIML are used for single character byte values and not strings. These are useful to access character in a string as a byte value.

  1. uint8 c = 'A'; // can also use uint, int or auto, or even string
  2. log("char: " + c); // char: 65
  3.  
  4. string s1 = "B";
  5. log("char: " + s1); // char: B
  6.  
  7. string s2 = 'C';
  8. log("char: " + s2); // char: 67 (s2 is a string holding "67")
  9.  
  10. string s3 = "ABC";
  11. s3[1] = 65;
  12. s3[2] = 'A';
  13. log("result: " + s3); // result: AAA
  14. log("s3[0] = "+s3[0]); // s3[0] = 65

The normal strings are written between double quotation marks ("). Inside the constant strings some escape sequences can be used to write exact byte values that might not be possible to write in your normal editor.

Sequence Value Description
\0 0 null character
\\ 92 back-slash
\' 39 single quotation mark (apostrophe)
\" 34 double quotation mark
\n 10 new line feed
\r 13 carriage return
\t 9 tab character
\xFF 0xFF FF is a 1 or 2 digit hexadecimal number representing the value wanted
\uFFFF
\UFFFFFFFF
0xFFFF
0xFFFFFFFF
FFFF(FFFF) is a hexadecimal number representing the unicode code point

The escape sequences \u and \U will add the specified unicode code point as a UTF-8 encoded sequence. Only valid unicode 5.1 code points are accepted, i.e. code points between U+D800 and U+DFFF (reserved for surrogate pairs) or above U+10FFFF are not accepted.

  1. string s1 = "This is ASCII 65 in hex: \x41, and \"escaped \\ chars\".";
  2. log(s1); // This is ASCII 65 in hex: A, and "escaped \ chars".
  3.  
  4. s1 = "This has unicode \u0230 \u03E1 \u0498 \U0000266B \U0000222B characters";
  5. log(s1); // This has unicode Ȱ ϡ Ҙ ♫ ∫ characters
  6.  
  7. string s2 = "This is a way to \0 finish the string.";
  8. log("len: " + s2.length + " | " +s2 + "|"); // len: 37 | This is a way to
  9. log("try 0 char"); // len: 37 | This is a way to try 0 char
  10.  
  11. for(uint i=0;i<s2.length;i++) { if (s2[i]==0) s2[i]='-'; } // replace 0 with 45
  12. log(s2); // This is a way to - finish the string.

The heredoc strings are designed for inclusion of large portions of text without processing of escape sequences. A heredoc string is surrounded by triple double-quotation marks ("""), and can span multiple lines of code. If the characters following the start of the string until the first linebreak only contains white space, it is automatically removed by the compiler. Likewise if the characters following the last line break until the end of the string only contains white space this is also removed.

  1. string s = """
  2. This is some text without "escape sequences". This is some text.
  3. This is some text. This is some text. This is some text. This is
  4. some text. This is some text. This is some text. This is some
  5. text. This is some text. This is some text. This is some text.
  6. This is some text.
  7. """;
  8. log(s); // (preserved spaces (begin) and newlines (end of lines))

Heredoc strings are very useful in Plug'n Script to parse a VARIABLE containing Windows-style path.

  1. string s1 = "$PLUGIN_DATA_PATH$"; // backslashes are interpreted as escape-chars
  2. log(s1); // C:rogram Filesommon FilesST3C Plug'n Script VST3 data
  3.  
  4. string s2 = """$PLUGIN_DATA_PATH$"""; // backslashes are preserved
  5. log(s2); // C:\Program Files\Common Files\VST3\BC Plug'n Script VST3 data

If more than one string constants are written in sequence with only whitespace or comments between them the compiler will concatenate them into one constant.

  1. string s2 = "First line.\n" // this is a first line
  2. "Second line.\n"
  3. "Third line." // this is a third one
  4. " And still a third";
  5. log(s2); // (outputs all as expected)

Original documentation

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


Comments

Please, authorize to view and post comments.

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