xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

TokenAt()

Returns the start and end position of a token.

Syntax

TokenAt( [<lNextDelimiter>], ;
         [<nCount>]        , ;
         [@<cTokenEnv>]      ) --> nPosition

Arguments

<lNextDelimiter>
This parameter defaults to .F. (false) which causes the function to return the start position of the token found with TokenNext(). When set to .T. (true) the function returns the position of the next delimiter following the found token.
<nTokenPos>
Optionally, a numeric value can be passed indicating the ordinal position of the token to retrieve. By default, the position of the current token found with TokenNext() is returned.
@<cTokenEnv>
Optionally, a character string holding a local tokenizer environment can be passed. It is obtained via the fourth parameter of TokenInit(). <cTokenEnv> must be passed by reference. If <cTokenEnv> is omitted, the function uses the global tokenizer environment.

Return

The function returns either the position of the token found with TokenNext() (default) or the position of the following delimiter as a numeric value.

Info

See also:TokenInit(), TokenNext()
Category: CT:String manipulation , Character functions , Token functions
Source:ct\token2.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example determines the start and end position of the second
// token in a string and extracts it with function SubStr().

    PROCEDURE Main
       LOCAL cIPAddr := "189.88.3.256"
       LOCAL cTokenEnv, nStart, nEnd

       TokenInit( cIPAddr, ".", @cTokenEnv )

       ? nStart := TokenAt( .F., 2, @cTokenEnv )  // result: 5
       ? nEnd   := TokenAt( .T., 2, @cTokenEnv )  // result: 7

       ? SubStr( cIPAddr, nStart, nEnd-nStart )   // result: 88
    RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe