xHarbour Reference Documentation > Function Reference |
Returns the numeric value of a digit at a specified position in a string.
ValPos( <cString>, [<nPos>] ) --> nValue
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.
See also: | [ ] (string), AscPos(), Val() |
Category: | CT:String manipulation , Character functions |
Source: | ct\ascpos.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com