| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Determines the ASCII code of a specified character in a string.
AscPos( <cString>, [<nPos>] ) --> nASCIICode
The function returns the ASCII code of the character at the specified position as a numeric value.
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), Asc() |
| 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
// ASCII code of a single character in a string.
PROCEDURE Main
LOCAL cString := "xHarbour"
// compatibility
? AscPos( cString ) // result: 114
? AscPos( cString, 2 ) // result: 72
// xHarbour [] operator
? Asc( cString[-1] ) // result: 114
? Asc( cString[2] ) // result: 72
RETURN
http://www.xHarbour.com