2.2.3.15.16 string::GetToken

Description

This member function returns the token at nToken index in a string where a token is separated by the delimiter specified by chDelimiter.

Syntax

string GetToken( int nToken, char chDelimiter = 0 )

Parameters

nToken
[input]An integer representing the token to get.
chDelimiter
[input]A character representing the delimiter.

Return

The extracted string token.

Examples

EX1

void string_GetToken_ex1()
{
	string str1("apples peaches pumpkins");
	string str3("apples,peaches,pumpkins");
	string str2=str1.GetToken(1);
	out_str(str2);//peaches
	
	string str4=str3.GetToken(2,',');
	out_str(str4);//pumpkins
}

Remark

This member function returns the token at nToken index in a string where a token is separated by the delimiter specified by chDelimiter. Default is 0 (null constant) so chDelimiter does not have to be specified when any white space (space, tab, newline, etc.) is to be used as the delimiter.

See Also

string::GetNumTokens, string::GetTokens

Header to Include

origin.h