Functions and Directives

Function LChar2Var() Foundation

Converts a locale string into a value of a requested data type.

Syntax
LChar2Var( <cString>, <cValtype> ) --> xValue
Parameters
<cString>
<cString> is a character string to be converted. It must be formatted depending on the requested data type <cValtype> and the country-specific setting for that data type:
Formatting rules for LChar2Var()
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
<cValtype>
<cValtype> can be one of the letters "C", "D", "L", "N" and indicates the data type of the return value. The letter corresponds with the return value of the Valtype() function.
Return

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.

Description

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.

Examples
Converting locale strings
// 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 
Feedback

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.