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

CharRem()

CHARREM()

Removes characters from a string

Syntax

      CHARREM( <cDeleteThisCharacters>, <cString> ) -> cReducedString

Arguments

<cDeleteThisCharacters> specifies the characters that should be deleted in <cString>

<cString>) is the string that should be processed

Returns

<cReducedString> is a string where the characters specified in <cDeleteThisCharacters> are deleted

Description

The CHARREM() function deletes the characters specified in <cDeleteThisCharacters> from <cString>.

Examples

      ? CHARREM( " ", " 1  2  " )   // "12"
      ? CHARREM( "3y", "xyz123" )   // "xz12"

Tests

      CHARREM( " ", " 1  2  " ) == "12"
      CHARREM( "3y", "xyz123" ) == "xz12"

Compliance

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

Platforms

All

Files

Source is charonly.c, library is ct3.

Seealso

CHARONLY(), WORDONLY(), WORDREM()

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

CharRela()

CHARRELA

Correlates the character positions in paired strings

Syntax

       CHARRELA(<cSearchFor1>,<cString1>,<cSearchFor2>,
              <cString2>) --> nPosition

Arguments

<cSearchFor1> Designates the character that is searched for in <cString1>.

<cString1> Designates the character string to search with <cSearchFor1>.

<cSearchFor2> Designates the character that is searched for in <cString2>. <cString2> Designates the character string to search with <cSearchFor2>.

Returns

CHARRELA() returns the positions where <cSearchFor1> and <cSearchFor2> occur in the corresponding character strings.

Description

This function builds a relationship (CHAR RELAtion) between two character strings. It determines the positions where the characters in <cSearchFor1> appear in <cString1> and where the characters in <cSearchFor2> appear in <cString2>.

Note

. The function returns a value of 0 if no relationship is found.

Example

       Search for the first position in which a "b" appears in the first string
           and a "1" appears in the second:
           ? CHARRELA("b", "b b b b", "1", "bbb11111")      // 5

See also

CHARRELREP()

CharPix()

CHARPIX()

Gets the number of scan lines per character.

Syntax

      CHARPIX() --> nHeight

Returns

Returns the number of scan lines per character.

Description

Returns the number of scan lines per character.

Compliance

This function is xHarbour libct contrib

Platforms

DJGPP

Files

Source is video.c, library is libct.

CharOr()

CHAROR()

Combine corresponding ASCII value of two strings with bitwise OR

Syntax

      CHAROR( <[@]cString1>, <cString2> ) --> cOrString

Arguments

<[@]cString1> first string <cString2> second string

Returns

<cOrString> string with bitwise OR combined ASCII values

Description

The CHAROR() function constructs a new string from the two strings passed as parameters. To do this, it combines the ASCII values of the corresponding characters of both strings with a bitwise OR-operation and places a character in the resulting string whose ASCII value equals to the result of that operation. If the first string is passed by reference, the resulting string is stored in <cString1>, too. By setting the CSETREF()-switch to .T., the return value can be omitted. If <cString2> is shorter than <cString1> and the last character of <cString2> has been processed, the function restarts with the first character of <cString2>.

Examples

      // set the LSB
      ? charor( "012345678", chr( 1 ) ) // --> "113355779"
      ? charor( "012345678", chr( 1 ) + chr( 3 ) ) // --> "133357779"

Tests

      charor( "012345678", chr( 1 ) ) == "113355779"
      charor( "012345678", chr( 1 ) + chr( 3 ) ) == "133357779"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARNOT(), CHARAND(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()

CharOnly()

CHARONLY()

Intersectional set of two strings based on characters

Syntax

      CHARONLY( <cThisCharactersOnly>, <cString> ) -> cReducedString

Arguments

<cThisCharactersOnly> specifies the characters that must not be deleted in <cString>. <cString> is the string that should be processed

Returns

<cReducedString> A string with all characters deleted but those specified in <cThisCharactersOnly>.

Description

The CHARONLY() function calculates the intersectional set of two strings. To do this, it deletes all characters from <cString> that do not appear in <cThisCharacterOnly>.

Examples

      ? CHARONLY( "0123456789", "0211 - 38 99 77" )  //  "0211389977"
      ? CHARONLY( "0123456789", "0211/ 389 977" )    //  "0211389977"

Tests

      CHARONLY( "0123456789", "0211 - 38 99 77" ) == "0211389977"
      CHARONLY( "0123456789", "0211/ 389 977" )   == "0211389977"

Compliance

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

Platforms

All

Files

Source is charonly.c, library is ct3.

Seealso

CHARREM(), WORDONLY(), WORDREM()

CharOne()

CHARONE()

Reduce multiple occurences of a character to one

Syntax

      CHARONE( [<cCharactersToReduce>,] <cString> ) -> cReducedString

Arguments

[<cCharactersToReduce>] specifies the characters the multiple occurences of which should be reduced to one Default: All characters. <cString> specifies the processed string

Returns

<cReducedString> the string with the reduced occurences

Description

The CHARONE() function reduces multiple occurences of characters in <cString> to a single one. It is important to note that the multiple occurences must occur directly one behind the other. This behaviour is is in contrast to the CHARLIST() function.

Examples

      ? CHARONE( "122333a123" )      // "123a123"
      ? CHARONE( "A  B  CCCD" )      // "A B CD"
      ? CHARONE( " ", "A  B  A  B" ) // "A B A B"
      ? CHARONE( "o", "122oooB12o" ) // "122oB12o"

Tests

      CHARONE( "122333a123" )      == "123a123"
      CHARONE( "A  B  CCCD" )      == "A B CD"
      CHARONE( " ", "A  B  A  B" ) == "A B A B"
      CHARONE( "o", "122oooB12o" ) == "122oB12o"

Compliance

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

Platforms

All

Files

Source is charone.c, library is ct3.

Seealso

CHARREM(), WORDONE()

CharOdd()

CHARODD()

Returns the characters on the odd positions in a string

Syntax

      CHARODD( <cString> ) --> cOddString

Arguments

<cString> processed string

Returns

<cOddString> a string containing all character from odd positions in <cString>

Description

The CHARODD() function looks for the characters on the odd positions in a given string, collects them and returns them as a string.

Examples

      ? CHARODD( "H E L L O ! " ) // -> "HELLO!"

Tests

      CHARODD( "1A2B3C4D5E" ) == "12345"
      CHARODD( "1A2B3C4D5" )  == "12345"

Compliance

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

Platforms

All

Files

Source is charevod.c, library is ct3.

Seealso

CHAREVEN(), CHARMIX()

CharNot()

CHARNOT()

Process each character in a string with bitwise NOT operation

Syntax

      CHARNOT( <[@]cString> ) --> cNotString

Arguments

<[@]cString> string to be processed

Returns

<cNotString> string with bitwise negated characters

Description

The CHARNOT() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise NOT operation to the characters of the string and places a character in the resulting string whose ASCII value equals to the result of that operation. It can be easily seen that the resulting ASCII-value equals 255 minus input ASCII value. If the string is passed by reference, the resulting string is stored in <cString>, too. By setting the CSETREF()-switch to .T., the return value can be omitted.

Examples

      ? charnot( chr( 85 ) + chr( 128 ) + chr( 170 ) + chr( 1 ) ) 
// --> chr( 170 ) + chr( 127 ) + chr( 85 ) + chr( 254 ) ? charnot( charnot( "This is a test!" ) ) --> "This is a test!"

Tests

      charnot( chr( 85 ) + chr( 128 ) + chr( 170 ) + chr( 1 ) ) ==;
chr( 170 ) + chr( 127 ) + chr( 85 ) + chr( 254 ) charnot( charnot( "This is a test!" ) ) == "This is a test!"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

CHARADD(), CHARSUB(), CHARAND(), CHAROR(), CHARXOR(), CHARSHL(), CHARSHR(), CHARRLL(), CHARRLR(), CSETREF()