| 1 | [[TOC]] |
| 2 | = <lol/base/string.h> = |
| 3 | |
| 4 | View this file in the source browser: [browser:trunk/src/lol/base/string.h] |
| 5 | |
| 6 | == String == |
| 7 | |
| 8 | The `String` class encapsulates an array of chars representing '''UTF-8 characters'''. |
| 9 | |
| 10 | Strings can be constructed from other strings or from C-style strings: |
| 11 | |
| 12 | {{{ |
| 13 | #!cpp |
| 14 | String s1; /* Will be empty */ |
| 15 | String s2("ABC"); /* Will contain "ABC" */ |
| 16 | String s3("ABC", 2); /* Will contain "AB" */ |
| 17 | String s4(s3); /* Will contain "AB" */ |
| 18 | }}} |
| 19 | |
| 20 | The length specifier helps building strings containing the null char: |
| 21 | |
| 22 | {{{ |
| 23 | #!cpp |
| 24 | String s1("abc\0def"); /* Will contain "abc" */ |
| 25 | String s2("abc\0def", 7); /* Will contain "abc\0def" */ |
| 26 | }}} |
| 27 | |
| 28 | The contents of a string can be accessed as a constant C string using the `C()` accessor: |
| 29 | |
| 30 | {{{ |
| 31 | #!cpp |
| 32 | String s("Hello!"); |
| 33 | printf("%s\n", s.C()); |
| 34 | }}} |