RANGEREM()

RANGEREM()

Remove characters within a certain ASCII range from a string

Syntax

       RANGEREM( <cChar1|nChar1>, <cChar2|nChar2>, <cString> ) -> cString

Arguments

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

<cString> Designates the character string that is edited.

Returns

The function returns the modified character string.

Description

RANGEREM() allows you to delete all characters that are in a particular ASCII range. For example, you could delete all control characters in a character string. The designated range can run “back to front”, meaning <cChar2|nChar2> can have a lower value than <cChar1|nChar1>. In such a case the range extends from the larger value to 255 and also from 0 to the smaller value.

Note

. Since the length of the character string is changed, passing by reference will not work here as it does with RANGEREPL().

Examples

        . ? rangerem( "0", "9", "year2002.dbf" )
                            // "year.dbf", remove all digits
        . ? rangerem( "9", "0", "year2002.dbf" )
                           // "22", testing removal from "9" to chr(255)
                           // and from chr(0) to "0"
        . ? rangerem( "0", "9", "yearcurr.dbf" )
                           // "yearcurr.dbf", test leaving string untouched
        .  Delete all control characters:
              cString   :=  RANGEREM(0, 31, cString)
        .  Delete all characters that are not upper case, alpha characters:
              cString   :=  RANGEREM(91, 64, cString)

Tests

       rangerem( "0", "9", "year2002.dbf" ) == "year.dbf"
            rangerem( "9", "0", "year2002.dbf" ) == "22"
            rangerem( "0", "9", "yearcurr.dbf" ) == "yearcurr.dbf"

Compliance

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

Platforms

All

Files

Source is range.c, library is libct.

Seealso

RANGEREPL()

POSRANGE()

POSRANGE()

Left-most position of a character from a set in a string

Syntax

       POSRANGE( <cChar1>, <cChar2>, <cString>, [<lMode>],
                      [<nIgnore>] ) -> nPosition

Arguments

<cCharacter1> and <cCharacter2> Designate the first and the last character of the character range.

<cString> Designates the string within which to search for a character in the <cCharacter1> to <cCharacter2> range.

<lMode> Designates if the return value is within the specified range or outside of the range. The default value (.F.) searches for the first character within the range.

<nIgnore> Designates the number of characters at the beginning of the character string that are excluded from the search. The default value excludes none (zero).

Returns

The value returned corresponds to the position of the located character. If no character is found, the function returns 0.

Description

Beginning from the left, POSRANGE() searches for the first character in the range <cCharacter1> to <cCharacter2> within <cString>. If <lMode> is specified as .T., then the function searches for the first character that is not in the specified range. This way you could search for control characters within a string by specifying <cCharacter1> = CHR(0) and <cCharacter2> = CHR(31). The <nIgnore> parameter gives you the ability to exclude a particular number of characters at the beginning of the <cString> from the search.

Examples

       .  Search for the first character in the character string cInput
              that is not a control character:
              cInput  :=  COM_READ(1)
              ? POSRANGE(CHR(0), CHR(31), cInput, .T.)
           .  Ignore the first 10 characters:
              ? POSRANGE(CHR(0), CHR(31), cInput, .T., 10)

Compliance

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

Platforms

All

Files

Source is pos1.c, library is libct.

Seealso

POSALPHA(), POSLOWER(), POSUPPER(), RANGEREPL()

WordRepl()

WordRepl()

Replacement of double characters

Syntax

      WordRepl( <cDoubleCharacterSearchString>, <[@]cString>,
                <cDoubleCharacterReplaceString>, [<lMode>] ) -> <cString>

Arguments

<cDoubleCharacterSearchString> is a string of double characters that should be replaced

<[@]cString>is the processed string

<cDoubleCharacterReplaceString> is a string of double characters that replace the one of <cSearchString>

[<lMode>] sets the replacement method (see description) Default: .F.

Returns

<cString> the processed string

Description

The WordRepl() takes the double characters of <cDoubleCharacterSearchString> one after the other and searches for them in <cString>. For <lMode> set to .F., this search is successful, if the double character sequence in <cString> starts at an odd position or at any position, if <lMode> is set to .T.

If this happens, the double character sequence will be replaced with the corresponding double character sequence of <cDoubleCharacter ReplaceString>. If <cDoubleCharacter ReplaceString> is shorter than <cDoubleCharacter SearchString> the last double sequence of <cDoubleCharacter ReplaceString> is used for the “rest” of <cDoubleCharacter SearchString>. Note that the last double character sequence in “AABBC” is “BB” in this context !!

After the replacement the function restarts the search in <cString> BEHIND the replacement if the CSETATMUPA() switch is turned off, or BEHIND the first character of the replacement if the switch is turned on. (see examples for this !) One can omit the return value of this function by setting the CSETREF() to .T., but one must then pass <cString> by reference to get a result.

Examples

      ? WordRepl( "CC", "AABBCCDDEE", "XX" ) // "AABBXXDDEE"
      ? WordRepl( "aa", "1aaaa", "ba" )      // "1abaa"
      ? WordRepl( "aa", "1aaaa", "ba", .T. ) // "1baba"
      csetatmupa( .T. )
      ? WordRepl( "aa", "1aaaa", "ba" )      // "1abaa"
      ? WordRepl( "aa", "1aaaa", "ba", .T. ) // "1bbba"

Tests

      WordRepl( "CC", "AABBCCDDEE", "XX" ) == "AABBXXDDEE"
      WordRepl( "aa", "1aaaa", "ba" )      == "1abaa"
      WordRepl( "aa", "1aaaa", "ba", .T. ) == "1baba"
      Eval( {|| csetatmupa( .T. ), WordRepl( "aa", "1aaaa", "ba" ) } ) == "1abaa"
      Eval( {|| csetatmupa( .T. ), WordRepl( "aa", "1aaaa", "ba", .T. ) } ) == "1bbba"

Compliance

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

Platforms

All

Files

Source is wordrepl.c, library is ct3.

Seealso

CHARREPL(), RANGEREPL(), POSREPL(), CSETREF(), CSETATMUPA()

CSetRef()

CSetRef()

Determine return value of reference sensitive CT3 string functions

Syntax

      CSetRef( [<lNewSwitch>] ) -> lOldSwitch

Arguments

[<lNewSwitch>] .T. -> suppress return value .F. -> do not suppress return value

Returns

lOldSwitch old (if lNewSwitch is a logical value) or current state of the switch

Description

Within the CT3 functions, the following functions do not change the length of a string passed as parameter while transforming this string:

ADDASCII() BLANK() CHARADD() CHARAND() CHARMIRR() CHARNOT() CHAROR() CHARRELREP() CHARREPL() CHARSORT() CHARSWAP() CHARXOR() CRYPT() JUSTLEFT() JUSTRIGHT() POSCHAR() POSREPL() RANGEREPL() REPLALL() REPLLEFT() REPLRIGHT() TOKENLOWER() TOKENUPPER() WORDREPL() WORDSWAP()

Thus, these functions allow to pass the string by reference [@] to the function so that it may not be necessary to return the transformed string. By calling CSetRef (.T.), the above mentioned functions return the value .F. instead of the transformed string if the string is passed by reference to the function. The switch is turned off (.F.) by default.

Compliance

This function is fully CT3 compatible.

Platforms

All

Files

Source is ctstr.c, library is ct3.

Seealso

ADDASCII(), BLANK(), CHARADD(), CHARAND(), CHARMIRR(), CHARNOT(), CHAROR(), CHARRELREP(), CHARREPL(), CHARSORT(), CHARSWAP(), CHARXOR(), CRYPT(), JUSTLEFT(), JUSTRIGHT(), POSCHAR(), POSREPL(), RANGEREPL(), REPLALL(), REPLLEFT(), REPLRIGHT(), TOKENLOWER(), TOKENUPPER(), WORDREPL(), WORDSWAP()

CharRepl()

CHARREPL()

Replacement of characters

Syntax

      CHARREPL( <cSearchString>, <[@]cString>,
                <cReplaceString>, [<lMode>] ) -> cString

Arguments

<cSearchString> is a string of characters that should be replaced

<[@]cString> is the processed string

<cReplaceString> is a string of characters that replace the one of <cSearchString>

[<lMode>] sets the replacement method (see description) Default: .F.

Returns

<cString> the processed string

Description

The CHARREPL() function replaces certain characters in <cString> with others depending on the setting of <lMode>. If <lMode> is set to .F., the function takes the characters of <cSearchString> one after the other, searches for them in <cString> and, if successful, replaces them with the corresponding character of <cReplaceString>. Be aware that if the same characters occur in both <cSearchString> and <cReplaceString>, the character on a certain position in <cString> can be replaced multiple times. if <lMode> is set to .T., the function takes the characters in <cString> one after the other, searches for them in <cSearchString> and, if successful, replaces them with the corresponding character of <cReplaceString>. Note that no multiple replacements are possible in this mode. If <cReplaceString> is shorter than <cSearchString>, the last character of <cReplaceString> is used as corresponding character for the the “rest” of <cSearchString>. One can omit the return value by setting the CSETREF() switch to .T., but then one must pass <cString> by reference to get the result.

Examples

      ? charrepl( "1234", "1x2y3z", "abcd" )            // "axbycz"
      ? charrepl( "abcdefghij", "jhfdb", "1234567890" ) // "08642"
      ? charrepl( "abcdefghij", "jhfdb", "12345" )      // "55542"
      ? charrepl( "1234", "1234", "234A" )              // "AAAA"
      ? charrepl( "1234", "1234", "234A", .T. )         // "234A"

Tests

      charrepl( "1234", "1x2y3z", "abcd" ) == "axbycz"
      charrepl( "abcdefghij", "jhfdb", "1234567890" ) == "08642"
      charrepl( "abcdefghij", "jhfdb", "12345" ) == "55542"
      charrepl( "1234", "1234", "234A" ) == "AAAA"
      charrepl( "1234", "1234", "234A", .T. ) == "234A"

Compliance

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

Platforms

All

Files

Source is charrepl.c, library is ct3.

Seealso

WORDREPL(), POSREPL(), RANGEREPL(), CSETREF()

Harbour All Functions – R

RangeRem

RangeRepl

RAt

Rate

RD / RMDIR / DirRemove

ReadKey

ReadVar()

RecCount

RecNo
RecSize

RemAll

RemLeft
RemRight
ReplAll
Replicate

ReplLeft

ReplRight

RestToken
Right

RLock

Round

Row

RToD

RTrim

String Functions

AddASCII

AfterAtNum

AllTrim
Asc

ASCIISum

ASCPos
At

AtAdjust

AtNum
AtRepl
AtToken

BeforAtNum

Chr

CharAdd
CharAnd
CharEven
CharHist
CharList
CharMirr
CharMix
CharNoList
CharNot
CharOdd
CharOne
CharOnly
CharOr
CharPix
CharRela
CharRelRep
CharRem
CharRepl
CharRLL
CharRLR
CharSHL
CharSHR
CharSList
CharSort
CharSub
CharSwap
CharWin
CharXOR

CountLeft
CountRight
Descend
Empty
hb_At
hb_RAt
hb_ValToStr
IsAlpha
IsDigit
IsLower
IsUpper

JustLeft
JustRight

Left
Len
Lower
LTrim

NumAt
NumToken
PadLeft
PadRight

PadC
PadL
PadR

POSALPHA
POSCHAR
POSDEL
POSDIFF
POSEQUAL
POSINS
POSLOWER
POSRANGE
POSREPL
POSUPPER

RangeRem
RangeRepl

RAt

RemAll

RemLeft
RemRight
ReplAll

Replicate

ReplLeft

ReplRight

RestToken

Right
RTrim

SaveToken

SetAtLike
Space
Str

StrDiff

StrFormat

StrSwap

StrTran
StrZero
SubStr

TabExpand
TabPack

Token

TokenAt
TokenEnd
TokenExit
TokenInit
TokenLower
TokenNext
TokenNum
TokenSep
TokenUpper

Transform
Trim
Upper
Val

ValPos
WordOne
WordOnly
WordRem
WordRepl
WordSwap

WordToChar