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

Advertisements

2 responses to “RANGEREPL()

  1. Pingback: Harbour All Functions – R | Viva Clipper !

  2. Pingback: Harbour String Functions | 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s