REPLRIGHT()

REPLRIGHT()

Replace certain characters at the right of a string

Syntax

      REPLRIGHT( <cString>, <cReplace|nReplace>, [<cSearch|nSearch>] )
                     -> cString

Arguments

<cString> [@] Designates the string that is processed.

<cReplace|nReplace> Designates the character that replaces the character in <cSearch|nSearch> at the end of the <cString>.

<cSearch|nSearch> Designates the character at the end of <cString> that is replaced by <cReplace|nReplace>. The default value is a space, CHR(32).

Returns

The processed <cString> is returned.

Description

REPLRIGHT() can be used to exchange all trailing characters in a string for any character choosen.

Note

. The return value of this function can be suppressed by implementing CSETREF() to save space in working memory.

Examples

       .  Replace the trailing spaces with dashes:
          ? REPLRIGHT("abcd  ", "-")        // "abcd--"
       .  Replace the trailing dashes with spaces:
          ? REPLRIGHT("abcd--", " ", "-")   // "abcd  "
       .  Replace only the trailing spaces:
          ? REPLRIGHT("   1  ", "-")        // "   1--"

Compliance

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

Platforms

All

Files

Source is replace.c, library is libct.

Seealso

REPLALL(), REPLLEFT(), CSETREF(), Introduction

REPLLEFT()

REPLLEFT()

Replace certain characters at the left of a string

Syntax

      REPLLEFT( <cString>, <cReplace|nReplace>,
                                [<cSearch|nSearch>] ) -> cString

Arguments

<cString> [@] Designates the string that is processed.

<cReplace|nReplace> Designates the character that replaces the character in <cSearch|nSearch> at the beginning of the <cString>.

<cSearch|nSearch> Designates the character at the beginning of <cString> that is replaced by <cSearch|nSearch>. The default value is a

space, CHR(32).

Returns

The processed <cString> is returned.

Description

REPLLEFT() can be used to exchange all leading characters in a string for any other selected character.

Note

. The return value of this function can be suppressed by implementing CSETREF() to save space in working memory.

Examples

       .  Replace the leading spaces with zeros:
          ? REPLLEFT("  1234", "0")              // "001234"
       .  Replace the leading zeros with spaces:
          ? REPLLEFT("001234", " ", "0")         // "  1234"
       .  Replace only the leading spaces:
          ? REPLLEFT("  1    ", "0")             // "001   "

Compliance

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

Platforms

All

Files

Source is replace.c, library is libct.

Seealso

REPLALL(), REPLRIGHT(), CSETREF(), Introduction

REPLALL()

REPLALL()

Replace certain characters at the left and right of a string

Syntax

      REPLALL( <cString>, <cReplace|nReplace>,
              [<cSearch|nSearch>] ) -> cString

Arguments

<cString> [@] Designates the string that is processed.

<cReplace|nReplace> Designates the character that replaces the character in <cSearch|nSearch> at the beginning and end of <cString>.

<cSearch|nSearch> Designates the character at the beginning and end of <cString> that is replaced by <cReplace|nReplace>. The default value designates a space, CHR(32).

Returns

The processed <cString> is returned.

Description

REPLALL() can be used to exchange all leading and trailing spaces in a character string for any other character. Notice that the first non- replaceable character in either direction causes REPLALL() to stop replacing characters on that side.

Note

. The return value of this function can be suppressed by implementing CSETREF() to save space in working memory.

Examples

      .  Replace spaces with dashes.  Replace the spaces 
         only on the side where the character was found:
         ? REPLALL("abcd  ", "-")           // "abcd--"
      .  Replace zeros with spaces:
         ? REPLALL("001234", " ", "0")      // "  1234"
      .  Replace the blanks with dashes on both sides:
         ? REPLALL("   d  ", "-")           // "---d--"
      .  Replace only continuous sequences of characters at the
         beginning and the end of the character string:
         ? REPLALL(" d d  ", "-")           // "-d d--"

Compliance

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

Platforms

All

Files

Source is replace.c, library is libct.

Seealso

REPLLEFT(), REPLRIGHT(), CSETREF(), Introduction

RANGEREPL()

RANGEREPL()

Replace characters within a certain ASCII range from a string

Syntax

       RANGEREPL( <cChar1|nChar1>, <cChar2|nChar2>,
           <[@]cString>, <cReplacementChar|nReplacementChar> ) 
           -> cString

Arguments

<cChar1|nChar1> and <cChar2|nChar> Designate the first and the last character of the character range.

<cString> [@] Designates the string that is processed.

<cReplacementChar|nReplacementChar> Designates the single character that replaces those characters in <cString> that are within the specified range.

Returns

The processed character string is returned.

Description

All characters that are in a particular range can be replaced by a new character. For example, you could replace all control characters with spaces. The designated range can also run from “back to front”, meaning that <cChar2|nChar2 can have a lower value than <cChar1|nChar1. In such a case the range extends from the larger value to 255 and from 0 to the smaller value.

Notes

. The length of <cString> remains unaffected by this function. . The return value of this function can be suppressed by implementing CSETREF() to save room in working memory.

Examples

        . ? rangerepl( "0", "9", "year2002.dbf", "?" )
                              // "year????.dbf", replace all digits
        . ? rangerepl( "9", "0", "year2002.dbf", "?" )
                  // "????2??2????", testing replacement from
                  // "9" to chr(255) and from chr(0) to "0"
        . ? rangerepl( "0", "9", "yearcurr.dbf", "?" )
                  // "yearcurr.dbf", test leaving string untouched
        .  Exchange all control characters in a character string for the
              character ".":
              cString  :=  "a" + CHR(5) + "b" + CHR(9)
              ? RANGEREPL(CHR(0), CHR(31), cString, ".")   // "a.b."
        .  A null string can be specified, instead of CHR(0).  The
           following example exchanges all characters with a code < "A" for
           the number "0".  Of course, the number "0" remains the number "0":
           ? RANGEREPL("", CHR(65), "123400", "0")      // "000000"
        .  All characters in the range "0" to "8" are exchanged for the
           number "9":
           ? RANGEREPL("0", "8", "0212 - 78 67 43", "9")
                                                        // "9999 - 99 99 99"
        .  With the exception of upper case letters, all characters are
           exchanged for dashes.  The optimum call is in conjunction with
           CSETREF():
           CSETREF(.T.)
           cString  :=  "A()&BC/?D"
           RANGEREPL(91, 64, @cString, "-")             // "A--BC--D"

Tests

       rangerepl( "0", "9", "year2002.dbf", "?" ) == "year????.dbf"
       rangerepl( "9", "0", "year2002.dbf", "?" ) == "????2??2????"
       rangerepl( "0", "9", "yearcurr.dbf", "?" ) == "yearcurr.dbf"

Compliance

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

Platforms

All

Files

Source is range.c, library is libct.

Seealso

RANGEREM(), POSREPL(), CHARREPL(), CSETREF(), Introduction

JustRight()

JustRight()

Move characters from the end to the beginning of a string

Syntax

       JustRight( <[@]cString>, [<cChar>|<nChar>] ) -> cJustifiedString

Arguments

<cString> [@] Designates the string that is processed. <cCharacter|nCharacter> Designates the character that is moved from the end of the <cString> to the beginning. The default value is a space, CHR(32).

Returns

The processed <cString> is returned.

Description

JustRight() moves the characters specified in <cCharacter| nCharacter> from the end of a character string to the beginning. Then the remaining text in the character string is right justified, without affecting the length.

Notes

. If the <cCharacter|nCharacter> parameter is not specified, spaces are automatically moved. . The return value for this function can be suppressed by implementing CSETREF() to save room in working memory.

Examples

       .  Move the blanks
              ? JustRight("123   ")           // "   123"
           .  Move the "." character
              ? JustRight("123..", ".")       // "..123 "

Compliance

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

Platforms

All

Files

Source is justify.c, library is libct.

Seealso

JustLeft(), CSetRef(), Introduction

JustLeft()

JustLeft()

Moves characters from the beginning to the end of a string

Syntax

       JustLeft( <[@]cString>, [<cChar>|<nChar>] ) -> cJustifiedString

Arguments

<cString> [@] Designates the string that is processed. <cCharacter|nCharacter> Designates the character that is moved from the beginning of the <cString> to the end. The default value is a space, CHR(32).

Returns

The processed <cString> is returned.

Description

JustLeft() moves the characters specified in <cCharacter|nCharacter> from the beginning of a character string to the end. Then the remaining text in the character string is left justified, without affecting the length.

Notes

. If the <cCharacter|nCharacter> parameter is not specified, spaces are automatically moved. . The return value for this function can be suppressed by implementing CSETREF() to save room in working memory.

Examples

       .  Move the blanks:
              ? JustLeft("   123")              // "123   "
           .  Move the "." character:
              ? JustLeft("..123","." )          // "123.."

See also

JustRight(), CSetRef(), Introduction

CharWin()

CHARWIN()

Exchanges particular characters in a screen area.

Syntax

       CHARWIN([<nTopline>,<nLeftcolumn>,<nBottomline>,
              <nRightcolumn>, [<cNewcharacter|nNewcharacter>],
              [<cOldcharacter|nOldcharacter>]]) --> cNull

Arguments

<nTopline> Designates the line for the top-left corner of the area.

<nLeftcolumn> Designates the column for the top-left corner the area.

<nBottomline> Designates the line for the bottom-right corner of the area.

<nRightcolumn> Designates the column for the bottom-right corner of the area.

<cNewcharacter|nNewcharacter> Designates the new character for the screen area. Specify the parameter as a numeric in the range of 0 to 255 or as a character string. The default value is the CLEARB.

<cOldcharacter|nOldcharacter> Designates which character to exchange. Specify the parameter as a numeric in the range of 0 to 255 or as a character string. The default is to exchange all characters.

() When no parameter is designated, the function replaces all characters in the screen area with CLEARB.

Returns

The function always returns a null string.

Description

Within a screen area, CHARWIN() replaces all characters or just a particular character with a new one. If <cNewcharacter|nNewcharacter> is not designated, the function uses the character set with SETCLEARB(), where the preset value is CHR(255). The upper-left and lower-right corner rows and columns are given for the borders of the area. If these arguments are missing, then the entire screen area is exchanged.

Examples

       .  Exchange all characters for CLEARB:
              SETCLEARB("X")       // Exchanges within CHARWIN() entire screen
           .  Exchange all "A" for "B":
              CHARWIN(10, 10, 20, 70, "B", "A")    // Always returns a ("") null
                                                   // string
           .  Numeric characters can also be designated:
              CHARWIN(10, 10, 20, 70, 66, 65)      // A = 65, B = 66

See also

SETCLEARB(), COLORWIN(), Introduction

CharRelRep()

CHARRELREP()

Replaces characters in a string depending on their correlation

Syntax

       CHARRELREP(<cSearchFor1>,<cString1>,<cSearchFor2>,
              <cString2>,<cReplaceExpression>) --> cString

Arguments

<cSearchFor1> Designates one or more characters within <cString1> for which to search.

<cString1> Designates the character string where <cSearchFor1> is found. <cSearchFor2> Designates one or more characters within <cString2> for which to search.

<cString2> [@] Designates the character string where <cSearchFor2> is found.

<cReplaceExpression> Designates one or more characters to replace those at the established corresponding position within <cString2>.

Returns

The processed <cString2> is returned.

Description

This function is easier to use than it seems. If we proceed on the assumption that both search expressions and the replacement expression are only one character long, then the following steps occur: . All positions are determined where <cSearchFor1> is found within <cString1>. . All positions are found where <cSearchFor2> is found within <cString2>. . The character in the <cString2> string is replaced by the character in the <cReplaceExpression>. This function can be used to simplify work with variables that contain screen memory. If cPict1 contains the character “|”at position 34 and cPict2 contains the character “-” at the same position, then this position within cPict2 can be replaced with a new character, “+”‘, which represents the combination of the two. Multiple Exchanges Both search expressions and the replacement expression can be longer than one character. The previously described exchange procedure occurs repeatedly — initially with the first character in the three character strings, then with the second, and so on. The number of iterations is regulated by the length of <cSearchFor1>. If <cSearchFor2> or the <cReplaceExpression> are shorter, then the last byte is used again.

Notes

. The length of <cString2> determines the number of search procedures at any one time. The length of <cSearchFor1> determines the number of possible exchanges. . The return value of this function can be suppressed by implementing CSETREF() to save space in working memory. . A use for multiple replacement using CHARRELREP() can be found in the accompanying sample programs.

Example

       Determine every position where a "b" occurs in the first string and a
           "1" occurs in the second string.  The respective character is then
           exchanged for the one designated as the fifth parameter.
           ? CHARRELREP("b", "b b b b", "1", "bbb11111", "x")
                                                             //"bbb1x1x1"

See also

CHARRELA(), CSETREF(), Introduction