string::GetAt

Description

Return a single character specified by an index number.


Get a unicode character in the form of a string at specified position.

Syntax

char GetAt( int nIndex )

int GetAt( int nIndex, string & str )

Parameters

nIndex
[input] Zero-based index of the character in the string object. The nIndex parameter must be greater than or equal to 0 and less than the value returned by GetLength.

nIndex
[input] position in string, see Remark
str
[output] unicode character

Return

A char containing the character at the specified position in the string.


0 if index specified is invalid, 1 if character is ANSI, 2 if character is Unicode

Examples

EX1

void string_GetAt_ex1()
{
    string str( "abcdef" );
    char chRet = str.GetAt(2);
        printf("%c\n", chRet);// print: c
}


EX2

void GetAt_ex2()
{
        Worksheet wks;
        wks.Create("origin");
        
        vector<string> vs = {"qw", "er", "ty"};
        wks.Columns(0).PutStringArray(vs);
        
        for(int nRow = 0; nRow < 3; nRow++)
        {
                string str1 = wks.TCell(nRow, 0);      
                string str2;
                str1.GetAt(1, str2);
                wks.SetCell(nRow, 1, str2);
        }
}

Remark

Index can be either byte offset, or character offset, dependent on the system variable @SCOC, which is typicalled controlled by the macro ENABLE_STR_LENGTH_USE_CHAR_COUNT

See Also

string::SetAt, string::GetLength

header to Include

origin.h