Difference between revisions of "GetSubString"

From NWN Lexicon
Jump to: navigation, search
m (Wikified article formatting)
(Getting a substring longer than the string is not an error)
 
Line 25: Line 25:
 
===Remarks===
 
===Remarks===
 
The parameter nOffset begins with 0 for the first character in a string, 1 for the second character, 2 for the third character and so on.
 
The parameter nOffset begins with 0 for the first character in a string, 1 for the second character, 2 for the third character and so on.
 +
 +
This does not yield an error if there are not nCount characters between nOffset and the end of the string. Only the remaining characters are returned.
  
 
===Version===
 
===Version===
Line 41: Line 43:
 
     // say "World!"
 
     // say "World!"
 
     SpeakString(GetSubString(sString, 6, 6));
 
     SpeakString(GetSubString(sString, 6, 6));
 +
 +
    // say "Hello World!"
 +
    // works even though there are not 50 characters in sString
 +
    SpeakString(GetSubString(sString, 0, 50));
 
}
 
}
 
</nwscript>
 
</nwscript>

Latest revision as of 15:40, 3 February 2020

Get a substring from within a string.

string GetSubString(
    string sString,
    int nOffset,
    int nCount
);

Parameters

sString
Target string.
nOffset
Character offset.
nCount
Number of characters in substring.

Description

Returns a substring of sString containing nCount characters starting from offset nOffset. Returns an empty string on error.

Remarks

The parameter nOffset begins with 0 for the first character in a string, 1 for the second character, 2 for the third character and so on.

This does not yield an error if there are not nCount characters between nOffset and the end of the string. Only the remaining characters are returned.

Version

1.22

Example

void main()
{
    string sString = "Hello World!";
 
    // say "Hello"
    SpeakString(GetSubString(sString, 0, 5));
 
    // say "World!"
    SpeakString(GetSubString(sString, 6, 6));
 
    // say "Hello World!"
    // works even though there are not 50 characters in sString
    SpeakString(GetSubString(sString, 0, 50));
}

See Also

functions:  FindSubString, GetStringRight, GetStringLeft

 author: Kristian Markon, editor: Daniel Beckman