Data type | String must be formatted according to |
---|---|
Date | SET DATE or SetLocale() for date values |
Logic | SetLocale() for logical values |
Numeric | SetLocale() for decimal separator, thousand separator is not allowed |
Function LChar2Var() Foundation
Converts a locale string into a value of a requested data type.
LChar2Var( <cString>, <cValtype> ) --> xValue
The data type of the return value is the requested data type. If <cString> is not a valid string representation of the requested data type and the current locale settings, the function returns NIL.
The function converts a character string formatted as the localized string representation of another data type to a value of this data type. It is used in conjunction with Var2LChar() which is the inverse function. Note, however, that LChar2Var() operates only on the simple data types Character, Date, Numeric and Logic, while Var2LChar() converts values of any data type to a locale string. If the first parameter <cString>does not contain a legal string representation of the requested data type, the function returns NIL.
// The example demonstrates the conversion of locale
// strings into Date, Logic and Numeric values.
#include "Nls.ch"
PROCEDURE Main
LOCAL cNumber := "6543,21"
LOCAL cDate := "01/22/00"
LOCAL cLogic := "Y"
SET DATE TO AMERICAN
SET EPOCH TO 1980
SET CENTURY ON
SetLocale( NLS_SDECIMAL , "," )
SetLocale( NLS_SYES , "Y" )
? LChar2Var( cNumber, "N" ) // result: 6543.21
? LChar2Var( cDate , "D" ) // result: 01/22/2000
? LChar2Var( cLogic , "L" ) // result: .T.
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.