XToC()

XToC()

Convert an expression to character type string

Syntax

       XToC( <expValue> ) --> cValue

Arguments

<expValue> Designate an expression of some of the following data type: NUMBER, CHARACTER, DATE, LOGICAL.

Returns

XToC() return a string with the representation of data type of expValue.

Description

At first glance, the XTOC() function does not appear to accomplish anything that cannot be done with the other functions. However, the advantage lies in the fact that you do not have to pay attention to the input data types. For example, you can convert the data in every field within a loop into a string. You could then link these into a longer string and use them to index or for comparisons. Each data type always returns a string with a particular fixed length:

       Each data type always returns a string with a particular fixed length:
       ----------------------------------------------------------
       Data Type Result Length    Similar function
       ---------------- --------- -------------------------------
       Numeric          8         FTOC()
       Logical          1
       Date             8         DTOS()
       String           Unchanged
       --------------- --------- -------------------------------

Examples

       .  In the case of logical parameters, XTOC() works like LTOC():
          ? XTOC(.T.)                              // "T"
          ? XTOC(.F.)                              // "F"
       .  Numeric values always return an 8-byte string:
          ? XTOC(0)                                // Length 8
          ? XTOC(9.9)                              // Ditto
          ? XTOC(-9.9)                             // Ditto
          ? XTOC(99)                               // Ditto
          ? XTOC(-99)                              // Ditto
       .  A string returns the same string:
          ? XTOC("123ABCabc")                      // "123ABCabc"
       .  A date returns the ANSI date:
          ? XTOC(CTOD("12/31/99"))                 // "19991231"
          ? XTOC(CTOD("01/01/00")                  // "19000101"
       .  An empty or false date returns an empty string rather than a
          null string:
          ? XTOC(CTOD("  /  /  ")                  // "        "
          ? XTOC(CTOD("77/77/77")                  // "        "
       .  Show a function where all the fields in a database are
          combined into one string.  This way, you can do a complete 
          comparison of the two data strings:
          // All fields in a record combined into one string
            FUNCTION STRINGREC
             PRIVATE nI, nFieldNo, cField, cStringRec
             cStringRec := ""
             nFieldNo   := FCOUNT()                // Number of fields
             FOR nI = 1 to nFieldNo
               cField          := FIELD(nI)        //  Field name
               cStringRec := cStringRec + XTOC(&cField)
             NEXT nI
             RETURN (cStringRec)

Platforms

All

Files

Source is misc1.c, library is libct.

Seealso

NTOC(), FTOC()

2 responses to “XToC()

  1. Pingback: Harbour Conversion Functions | Viva Clipper !

  2. Pingback: Harbour All Functions – X | Viva Clipper !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.