xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

ValPos()

Returns the numeric value of a digit at a specified position in a string.

Syntax

ValPos( <cString>, [<nPos>] ) --> nValue

Arguments

<cString>
This is a character string containing digits.
<nPos>
Optionally, the ordinal position of the character to query can be specified as a numeric value. It defaults to Len(<cString>), the last character.

Return

The function returns the numeric value of the character (digit) at the specified position. If the character is not a digit or <nPos> is larger than Len(<cString>), the return value is zero.

Note:  the function exists for compatibility reasons. The [ ] operator can be applied to character strings in xHarbour and is more efficient for extracting a single character.

Info

See also:[ ] (string), AscPos(), Val()
Category: CT:String manipulation , Character functions
Source:ct\ascpos.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows two different ways of obtaining the
// numeric value of a single digit in a string.

   PROCEDURE Main
      LOCAL cString := "abc8def6"

      // compatibility
      ? ValPos( cString )        // result: 6
      ? ValPos( cString, 4 )     // result: 8

      // xHarbour [] operator
      ? Val( cString[-1] )       // result: 6
      ? Val( cString[4] )        // result: 8
   RETURN

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