| Next revision | Previous revision | ||
|
hpl3:community:scripting:classes:tstring [2015/11/05 11:24] abion47 created |
hpl3:community:scripting:classes:tstring [2015/11/06 04:00] (current) abion47 [Remarks] |
||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ^ Return Type ^ Function Name ^ Parameters ^ Description ^ | ^ Return Type ^ Function Name ^ Parameters ^ Description ^ | ||
| - | | uint64 | length | const | | | + | | uint64 | length | const | Returns the length of the tString. | |
| - | | void | resize | uint64 | | | + | | void | resize | uint64 | Resizes the tString, removing characters and adding null characters as necessary. | |
| ====Remarks==== | ====Remarks==== | ||
| - | Have some helpful descriptions to add to this class? Edit this page and add your insight to the Wiki! | + | A tString is the HPL3 type for storing strings, or sequences of characters. They are created through use of a string literal, or a series of characters surrounded by quotation marks ( " ). |
| + | <code=c++>tString sStr = "This is a string.";</code> | ||
| + | |||
| + | A thing to note is that a tString is essentially a wrapper for an array of characters, meaning that you can retrieve characters within a tString by using square bracket ( [ ] ) syntax. (Characters in the HPL3 engine are represented by unsigned 8-bit integers, or ''uint8''.) | ||
| + | |||
| + | <code=c++>uint8 c = sStr[1];</code> | ||
| + | |||
| + | A tString is [[wp>Null-terminated_string|null-terminated]], meaning that when a tString is read (for example, in a cLux_AddDebugMessage function), the tString will only process its characters until it reaches a null-character, and characters after the null-character, if any, are ignored. | ||
| + | |||
| + | <code=c++>sStr.resize(5); | ||
| + | sStr[0] = 'H'; | ||
| + | sStr[1] = 'i'; | ||
| + | sStr[2] = '\0'; // This is a null-character | ||
| + | sStr[3] = 'Q'; | ||
| + | sStr[4] = '9'; | ||
| + | cLux_AddDebugMessage(sStr); | ||
| + | |||
| + | // The message as printed: | ||
| + | // Hi</code> | ||