AngelScript

Strings

Observe: Strings are only available in the scripts if the application registers the support for them. The syntax for using strings may differ for the application you're working with so consult the application's manual for more details.

Strings hold an array of bytes or 16bit words depending on the application settings. 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, and the documentation strings, called heredoc strings.

The normal strings are written between double quotation marks (`"`) or single 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
`\xFFFF` | 0xFFFF | FFFF should be exchanged for a 1 to 4 digit hexadecimal number representing the value wanted. If the application uses 8bit strings then only values up to 255 is accepted.
`\uFFFF` | 0xFFFF | FFFF should be exchanged for the hexadecimal number representing the unicode code point
`\UFFFFFFFF` | 0xFFFFFFFF | FFFFFFFF should be exchanged for the hexadecimal number representing the unicode code point

      string str1 = "This is a string with \"escape sequences".";
      string str2 = 'If single quotes are used then double quotes can be included without "escape sequences".';

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 remove, including the linebreak.

      string str = """
      This is some text without "escape sequences". This is some text.
      This is some text. This is some text. This is some text. This is
      some text. This is some text. This is some text. This is some
      text. This is some text. This is some text. This is some text.
      This is some text.
      """;

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.

      string str = "First line.\n"
                   "Second line.\n"
                   "Third line.\n";

The escape sequences \u and \U will add the specified unicode code point as a UTF-8 or UTF-16 encoded sequence depending on the application settings. 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.

The standard string implementation also comes with the following methods:

      // Returns the length of the string
      uint length() const;

      // Assignment and concatenation
      string &opAssign(const string &in other);
      string &opAddAssign(const string &in other);
      string  opAdd(const string &in right) const;

      // Access individual characters
      uint8       &opIndex(uint);
      const uint8 &opIndex(uint) const;

      // Comparison operators
      bool opEquals(const string &in right) const;
      int  opCmp(const string &in right) const;

      // Substring
      string substr(uint start = 0, int count = -1) const;
      array<string>@ split(const string &in delimiter) const;

      // Search
      int findFirst(const string &in str, uint start = 0) const;
      int findLast(const string &in str, int start = -1) const;

      // Automatic conversion from primitive types to string type
      string &opAssign(double val);
      string &opAddAssign(double val);
      string  opAdd(double val) const;
      string  opAdd_r(double val) const;

      string &opAssign(int val);
      string &opAddAssign(int val);
      string  opAdd(int val) const;
      string  opAdd_r(int val) const;

      string &opAssign(uint val);
      string &opAddAssign(uint val);
      string  opAdd(uint val) const;
      string  opAdd_r(uint val) const;

      string &opAssign(bool val);
      string &opAddAssign(bool val);
      string  opAdd(bool val) const;
      string  opAdd_r(bool val) const;

There is also a standard global function joining an array of strings into a single string with delimeter.

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