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()

WordToChar()

WordToChar()

Replace double with single characters

Syntax

       WordToChar( <cDoubleCharacterSearchString>, <cString>,
                   <cSingleCharacterReplaceString> ) -> cString

Arguments

<cDoubleCharacterSearchString> Designates multiple 2-byte sequences which are exchanged for corresponding individual characters from the <cSingleCharacter ReplaceString>.

<cString> Designates the character string within which 2-byte sequences are exchanged for individual characters.

<cSingleCharacterReplaceString> Designates a sequence of individual characters which correspond to 2-byte sequences in <cDoubleCharacterSearchString> for replacement within <cString>.

Returns

WordToChar() returns the modified character string.

Description

When you use SOUNDEX algorithms, sequences of two characters must often be exchanged for a single other character. WordToChar() makes this process extremely simple and quick. The function processes the <cString> in 1-byte steps. The behavior after exchanging a sequence for a character is determined by CSetAtMuPa(). If CSetAtMuPa is .F., the search for more sequences continues after the exchanged characters. If CSetAtMuPa is .T., the search for more sequences continues and includes the exchanged characters.

Notes

. The term “word” is not used here in the textual sense, but rather as it is used in assembler programming. A “word” consists of units of 16 bits, or more precisely, 2 bytes. . <cCharacterlist> can be shorter than <cDoubleCharacterList>. When this occurs, the function exchanges the sequences in <cDoubleCharacterList> that do not have corresponding sequences in <cCharacterlist> for the last sequence in <cDoubleCharacterList>.

Examples

       .  This example shows a simple replacement:
              ? WordToChar("aa", "Xaaaa", "a")      // "Xaa"
       .  This example shows WORDTOCHAR() in conjunction with
          CSetAtMuPa():
          CSetAtMuPa(.F.)                       // Multi pass off
          ? WordToChar("aa", "Xaaaa", "a")      // "Xaa"
          CSetAtMuPa(.T.)                       // Multi pass on
          ? WordToChar("aa", "Xaaaa", "a")      // "Xa"

Compliance

WordToChar() is compatible with CT3’s WordToChar().

Platforms

All

Files

Source is wordtoch.c, library is libct.

Seealso

CSetAtMuPa(), CharRepl(), WordRepl()

Week()

Week()

Returns the calendar week a number

Syntax

      Week( [<dDate>][, <lSWN>] ) -> nWeek

Argument

<dDate> Designates a date for which the week it lies in, is determined. The default is the system date.

<lSWN> Simple Week Number ( see below description )

Returns

WEEK() returns a sequential week number that designates in which week of the year <dDate> lies.

Description

Week() returns the calendar week a number. If no date is specified, the system date is used. An empty date via hb_SToD(“”) returns 0. The week of the year in which a day lies is information required by a number of technical financial calculations or wage accounting. This function determines this week and acknowledged all calendar rules. If <lSWN> is .T., Week() will calculate the “simple week number”, defined by – week #1 starts on January, 1st – week #(n+1) starts seven days after start of week #n If <lSWN> is .F. (default), the ISO8601 week number, defined by – weeks start on mondays – week #1 is the one that includes January, 4 will be calculated.

Note

. When no date is specified, then WEEK() uses the system date. An empty date leads to a 0 result.

Example

       Determine the week for a date:
       dDate  :=  CTOD("03/14/92")
       ? "This date is in week:  ", WEEK(dDate)

Compliance

Week() is compatible with CT3’s Week(). <lSWN> is Harbour extention.

Platforms

All

Files

Source is dattime2.prg, library is libct.

Seealso

CDoW(), CToDoW(), DoW()

TabPack()

TabPack()

Pack fill characters to appropriate tab characters

Syntax

     TabPack( <cString>, [<nTabWidth>], [<cFillChar|nFillChar>],
             [<cNewLineCharacters>], [<cTabChar|nTabChar>],
             [<lIgnore141>] ) -> cPackedString

Arguments

<cString> String to alter <nTabWidth>

<cFillChar|nFillChar> Width of tab or character to use to fill <cNewLineCharacters> string indicating new line, default is the string returned by hb_eol()

<cTabChar|nTabChar> character indicating a tab stop, default is chr(9)

<lIgnore141> .T., if the soft-CR used by MEMOEDIT() should be ignored as a newline indicator, default is .F. (functions uses chr(141))

Returns

TABPACK() returns the modified character string.

Description

This function does not simply exchange a simple sequence of the same characters for a tab; instead, it takes into account the true tab positions. If a space (or the <cCharacter|nCharacter>) is found at a tab position, and immediately preceding it there is at least one identical character, the function replaces this sequence (maximum <nTabWidth>) with a CHR(9). With tab characters, text can be packed by individual tab widths. As with every good text editor, there is no replacement with a tab within single or double leading characters.

Notes

. For the beginning of a line, the function takes into account the “normal” carriage return (CHR(13)/CHR(10)) as well as the high bit return (CHR(141)) used by MEMOEDIT(). Previously existing tab characters are also taken into account. . If another tab already exists, this tab can be removed with TABEXPAND(). The new tab can then be inserted using TABPACK().

Example

       We have avoided replacing spaces with tabs in the following examples to
       keep the example legible.  Tab width is 8 (default).  "*" is exchanged
       for tab characters.
       ? TABPACK("AAAAAAA*", "*")           // "AAAAAAA*"
       ? TABPACK("AAAAA***", "*")           // "AAAAA" + CHR(9)
       ? TABPACK("AAAAA*****", "*")         // "AAAAA" + CHR(9) + "**"
       crlf   :=  CHR(13) + CHR(10)
       cText  :=  "ABCD+" + crlf + "++---+++++"
       ? TABPACK(cText, 4, "+")             // "ABCD+" + crlf +
                                            // "++---" + CHR(9) + "++"

Compliance

TabPack() is compatible with CT3’s TabPack(), but extended by Harbour; there are three new parameters for a better fine control of the function’s behaviour.

Platforms

All

Files

Source is tab.c, library is libct.

Seealso

TabExpand()

TabExpand()

TabExpand()

Replace tabulator control characters with fill characters

Syntax

       TabExpand(<cString>, [<nTabWidth>],
                [<cFillChar|nFillChar>],
                [<cNewLineCharacters>],
                [<cTabChar|nTabChar>],
                [<lIgnore141>]) -> cExpandedString

Arguments

<cString> String to alter

<nTabWidth> Tab width

<cFillChar|nFillChar> Fill Character

<cNewLineCharacters> string indicating new line, default is the string returned by hb_eol()

<cTabChar|nTabChar> character indicating a tab stop, default is chr(9)

<lIgnore141> .T., if the soft-CR used by MEMOEDIT() should be ignored as a newline indicator, default is .F. (functions uses chr(141))

Returns

The modified <cString> is returned.

Description

The TabExpand() function replaces all tab characters (CHR(9)) in <cString> with the corresponding number of spaces or <cCharacter| nCharacter>. The <nTabWidth> parameter can be used to set varying tab widths.

Notes

. In the absence of the <nTabWidth> parameter, TabExpand() has a default tab width of 8. . The carriage return and line feed, where the high bit is set, are taken into consideration. . SETTABS() does not affect this function.

Examples

       .  TabExpand() only fills to the next tab position:
          ? TabExpand("-" +CHR(9) +"!")                  // "-       !"
          ? TabExpand("----" +CHR(9) +"!")               // "----    !"
       .  You can fill with any character you like:
          ? TabExpand("-" +CHR(9) +"!", "+")             // "-+++++++!"
       .  The tab width can be selected:
          ? TabExpand("-" +CHR(9) +"!", 4)               // "-   !"
          ? TabExpand("----" +CHR(9) +"!", 8)            // "----    !"
          ? TabExpand("----" +CHR(9) +"!", 8, "+")       // "----++++!"

Tests

       TabExpand("-"+chr(9)+"!")             == "-       !"
       TabExpand("----"+chr(9) +"!")         == "----    !"
       TabExpand("-"+chr(9)+"!",, "+")       == "-+++++++!"
       TabExpand("-"+chr(9)+ "!", 4)         == "-   !"
       TabExpand("----"+chr(9)+ "!", 8)      == "----    !"
       TabExpand("----"+chr(9)+ "!", 8, "+") == "----++++!"
       TabExpand("-"+chr(9)+"!"+hb_eol()+"----"+chr(9)+ "!",, "+") 
                == "-+++++++!"+hb_eol()+"----++++!"

Compliance

TabExpand() is compatible with CT3’s TabExpand(), but there are three new parameters for a better fine control of the function’s behaviour.

Platforms

All

Files

Source is tab.c, library is libct.

Seealso

TabPack()