function GetSubString (string sString, int nStart, int nCount) Get nCount characters from sString, starting at nStart
* Return value on error: ""
* Return type: string
* Include file: nwscriptdefn
Attributes | Values |
---|
rdfs:label
| |
rdfs:comment
| - function GetSubString (string sString, int nStart, int nCount) Get nCount characters from sString, starting at nStart
* Return value on error: ""
* Return type: string
* Include file: nwscriptdefn
- The GetSubString() NWScript command extracts a portion of a string as a new string. If an error is encountered (such as trying to obtain a string of negative length), a zero-length string, "", is returned.
- Beware: invalid values for the nCount parameter can crash the game. NWN2 script doesn't support the idiom of leaving out the nCount parameter if the rest of the string from nStarts onwards is desired, and so the textbook method for getting the rest of a string from nStart onwards is this: string sRest = GetSubString(sString, nStart, GetStringLength(sString) - nStart); This should be safe provided that nStart is between 0 and the string length. Now, one might be tempted to avoid the overhead of the GetStringLength() call, and use a ploy common in other languages:
|
param3desc
| - The number of characters to be extracted.
|
dcterms:subject
| |
dbkwik:nwn2/proper...iPageUsesTemplate
| |
returns
| |
Name
| |
param
| - string sString
- int nStart
- int nCount
|
param2desc
| - The character of at which the substring begins. This is zero-based, so the first character is 0, the second is 1, etc.
|
param1desc
| - The string from which a substring will be extracted.
|
dbkwik:nwn/property/wikiPageUsesTemplate
| |
abstract
| - Beware: invalid values for the nCount parameter can crash the game. NWN2 script doesn't support the idiom of leaving out the nCount parameter if the rest of the string from nStarts onwards is desired, and so the textbook method for getting the rest of a string from nStart onwards is this: string sRest = GetSubString(sString, nStart, GetStringLength(sString) - nStart); This should be safe provided that nStart is between 0 and the string length. Now, one might be tempted to avoid the overhead of the GetStringLength() call, and use a ploy common in other languages: string sRest = GetSubString(sString, nStart, INT_MAX); This may work everywhere else, but in NWN2 it crashes the game hard. In cursory testing of GetSubString("GetSubString", 3, n); the game did not crash for n up to 500000000 and it did crash immediately for n = 600000000. However, this doesn't mean that values up to 500000000 are safe. It just means that the game didn't crash right away but there might still be undiscovered damage that could lead to a crash sometime later. Unless and until further information emerges, the only method that can be considered truly safe is the textbook method. Caveat emptor.
- function GetSubString (string sString, int nStart, int nCount) Get nCount characters from sString, starting at nStart
* Return value on error: ""
* Return type: string
* Include file: nwscriptdefn
- The GetSubString() NWScript command extracts a portion of a string as a new string. If an error is encountered (such as trying to obtain a string of negative length), a zero-length string, "", is returned.
|