TokenUpper()

TokenUpper()

Change the first letter of tokens to upper case

Syntax

      TokenUpper( <[@]cString>, [<cTokenizer>], [<nTokenCount>],
                  [<nSkipWidth>] ) -> cString

Arguments

<[@]cString> is the processed string

[<cTokenizer>] is a list of characters separating the tokens in <cString> Default: chr(0) + chr(9) + chr(10) + chr(13) + chr(26) + chr(32) + chr(32) + chr(138) + chr(141)+ “, .;:!\?/\\<>()#&%+-*”

[<nTokenCount>] specifies the number of tokens that should be processed Default: all tokens

[<nSkipWidth>] specifies the maximum number of successive tokenizing characters that are combined as ONE token stop, e.g. specifying 1 can yield to empty token Default: 0, any number of successive tokenizing characters are combined as ONE token stop

Returns

<cString> the string with the uppercased tokens

Description

The TokenUpper() function changes the first letter of tokens in <cString> to upper case. To do this, it uses the same tokenizing mechanism as the token() function. If TokenUpper() extracts a token that starts with a letter, this letter will be changed to upper case.

You can omit the return value of this function by setting the CSETREF() switch to .T., but you must then pass <cString> by reference to get the result.

Examples

      ? TokenUpper( "Hello, world, here I am!" )         
                 // "Hello, World, Here I Am!"
      ? TokenUpper( "Hello, world, here I am!",, 3 )     
                 // "Hello, World, Here I am!"
      ? TokenUpper( "Hello, world, here I am!", ",", 3 ) 
                 // "Hello, world, here I am!"
      ? TokenUpper( "Hello, world, here I am!", " w" )   
                 // "Hello, wOrld, Here I Am!"

Tests

      TokenUpper( "Hello, world, here I am!" )         == 
                  "Hello, World, Here I Am!"
      TokenUpper( "Hello, world, here I am!",, 3 )     == 
                  "Hello, World, Here I am!"
      TokenUpper( "Hello, world, here I am!", ",", 3 ) == 
                  "Hello, world, here I am!"
      TokenUpper( "Hello, world, here I am!", " w" )   == 
                  "Hello, wOrld, Here I Am!"

Compliance

TokenUpper() is compatible with CT3’s TokenUpper(), but a new 4th parameter, <nSkipWidth> has been added for synchronization with the the other token functions.

Platforms

All

Files

Source is token1.c, library is libct.

Seealso

TOKEN(), NUMTOKEN(), ATTOKEN(), TOKENLOWER(), TOKENSEP(), CSETREF()

TokenLower()

TokenLower()

Change the first letter of tokens to lower case

Syntax

      TokenLower( <[@]cString>, [<cTokenizer>], [<nTokenCount>],
                  [<nSkipWidth>] ) -> cString

Arguments

<[@]cString> is the processed string

[<cTokenizer>] is a list of characters separating the tokens in <cString> Default: chr(0) + chr(9) + chr(10) + chr(13) + chr(26) + chr(32) + chr(32) + chr(138) + chr(141) + “, .;:!\?/\\<>()#&%+-*”

[<nTokenCount>] specifies the number of tokens that should be processed Default: all tokens

[<nSkipWidth>] specifies the maximum number of successive tokenizing characters that are combined as ONE token stop, e.g. specifying 1 can yield to empty token Default: 0, any number of successive tokenizing characters are combined as ONE token stop

Returns

<cString> the string with the lowercased tokens

Description

The TokenLower() function changes the first letter of tokens in <cString> to lower case. To do this, it uses the same tokenizing mechanism as the token() function. If TokenLower() extracts a token that starts with a letter, this letter will be changed to lower case.

You can omit the return value of this function by setting the CSETREF() switch to .T., but you must then pass <cString> by reference to get the result.

Examples

      ? TokenLower( "Hello, World, here I am!" )         
                    // "hello, world, here i am!"
      ? TokenLower( "Hello, World, here I am!",, 3 )     
                    // "hello, world, here I am!"
      ? TokenLower( "Hello, World, here I am!", ",", 3 ) 
                    // "hello, World, here I am!"
      ? TokenLower( "Hello, World, here I am!", " W" )   
                    // "hello, World, here i am!"

Tests

      TokenLower( "Hello, World, here I am!" )         
               == "hello, world, here i am!"
      TokenLower( "Hello, World, here I am!",, 3 )     
               == "hello, world, here I am!"
      TokenLower( "Hello, World, here I am!", ",", 3 ) 
               == "hello, World, here I am!"
      TokenLower( "Hello, World, here I am!", " W" )   
               == "hello, World, here i am!"

Compliance

TokenLower() is compatible with CT3’s TokenLower(), but a new 4th parameter, <nSkipWidth> has been added for synchronization with the the other token functions.

Platforms

All

Files

Source is token1.c, library is libct.

Seealso

TOKEN(), NUMTOKEN(), ATTOKEN(), TOKENUPPER(), TOKENSEP(), CSETREF()

CharXOR()

CHARXOR()

Combine corresponding ASCII value of two strings with bitwise XOR

Syntax

      CHARXOR( <[@]cString1>, <cString2> ) --> cXOrString

Arguments

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

Returns

<cXOrString> string with bitwise XOR combined ASCII values

Description

The CHARXOR() 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 XOR-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

      // easy encryption
      ? charxor( "This is top secret !", "My Password" ) // --> <encrypted sentence>

Tests

      charxor( charxor( "This is top secret !", "My Password" ), "My Password" ) == "This is top secret !"

Compliance

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

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

CharSwap()

CHARSWAP()

Swap neighbouring characters in a string

Syntax

      CHARSWAP( <[@]cString> ) -> cSwappedString

Arguments

<[@]cString> is the string that should be processed

Returns

<cSwappedString> a string where neighbour characters are swapped

Description

The CHARSWAP() function loops through <cString> in steps of two characters and exchanges the characters from the odd and the even positions. By setting the CSETREF() switch to .T., one can omit the return value of this functin, but one must then pass <cString> by reference.

Examples

      ? CHARSWAP( "0123456789" )   // "1032547698"
      ? CHARSWAP( "ABCDEFGHIJK" )  // "BADCFEHGJIK"

Tests

      CHARSWAP( "0123456789" )  == "1032547698"
      CHARSWAP( "ABCDEFGHIJK" ) == "BADCFEHGJIK"

Compliance

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

Platforms

All

Files

Source is charswap.c, library is libct.

Seealso

WORDSWAP(), CSETREF()

CharSub()

CHARSUB()

Subtracts corresponding ASCII value of two strings

Syntax

      CHARSUB( <[@]cString1>, <cString2>) --> cSubString

Arguments

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

Returns

<cSubString> string with subtracted ASCII values

Description

The CHARSUB() function constructs a new string from the two strings passed as parameters. To do this, it subtracts the ASCII values of the corresponding characters of both strings and places a character in the resulting string whose ASCII value equals to that difference (modulo 256). 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

      ? charsub( "012345678", Chr( 1 ) ) // --> "/01234567"
      ? charsub( "123456789", Chr( 255 ) ) // --> "23456789:"
      ? charsub( "9999", Chr( 0 ) + Chr( 1 ) + Chr( 2 ) + Chr( 3 ) ) // --> "9876"

Tests

      charsub( "123456789", Chr( 1 ) ) == "012345678"
      charsub( "123456789", Chr( 1 ) + Chr( 2 ) ) == "002244668"
      charsub( "012345678", Chr( 255 ) ) == "123456789"
      charsub( "012345678", Chr( 255 ) + Chr( 254 ) ) == "133557799"

Compliance

CHARSUB() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

CharSort()

CHARSORT()

Sort sequences within a string.

Syntax

      CHARSORT( <[@]cString>, [<nElementLength>], [<nCompareLength>],
                [<nIgnoreCharacters>], [<nElemenOffset>], [<nSortLength>],
                [<lDescending>] ) -> cSortedString

Arguments

<[@]cString> is the string that should be processed

[<nElementLength>] specifies the length of the elements that should be sorted Default: 1

[<nCompareLength>] specifies how many characters within one element should be used for comparison Default: <nElementLength>

[<nIgnoreCharacters>] specifies the number of characters at the beginning of <cString> that should be ignored in the sort process Default: 0

[<nElementOffset>] specifies the offset of the comparison string within a element Default: 0 [<nSortLength>] specifies how many characters in <cString>, starting from the <nIgnoreCharacters> position, should be sorted Default: len(cString)-nIgnoreCharacters

[<lDescending>]) specifies whether the process should sort descending or not

Returns

<cSortedString> the string resulting from the sort process

Description

The CHARSORT function sorts the characters within a string <cString>. With the parameters <nIgnoreCharacters> and <nSortLength>, you can determine that only the substring from position <nIgnoreCharacters>+1 to position <nIgnoreCharacters>+<nSortLength> within <cString> should be sorted. The sorting algorithm is determined with the other parameters. <nElementLength> specifies the length of one element, i.e. there are <nSortLength>/<nElementLength> elements that are sorted. Note that surplus characters are not sorted but stay at their position. To do the sorting, the function uses the Quicksort algorithm implemented in the C-lib qsort() function. This algorithm needs to know how to compare and order two elements. This is done by comparing the ASCII values of a substring within each element. This substring is determined by the parameters <nElementOffset> and <nCompareLength> and the order by <lDescending>. By setting the CSETREF() switch to .T., one can omit the return value of the function, but one must then pass <cString> by reference.

Examples

      ? CHARSORT( "qwert" )                     // "eqrtw"
      ? CHARSORT( "qwert", 2 )                  // "erqwt"
      ? CHARSORT( "b1a4a3a2a1", 2, 1 )          // "a2a1a3a4b1"
      ? CHARSORT( "XXXqwert", 1, 1, 3 )         // "XXXeqrtw"
      ? CHARSORT( "b1a4a3a2a1", 2, 1, 0, 1 )    // "a1b1a2a3a4"
      ? CHARSORT( "384172852", 1, 1, 0, 0, 4 )  // "134872852"
      ? CHARSORT( "qwert", .T. )                // "wtrqe"

Tests

      CHARSORT( "qwert" )                     == "eqrtw"
      CHARSORT( "qwert", 2 )                  == "erqwt"
      CHARSORT( "b1a4a3a2a1", 2, 1 )          == "a2a1a3a4b1"
      CHARSORT( "XXXqwert", 1, 1, 3 )         == "XXXeqrtw"
      CHARSORT( "b1a4a3a2a1", 2, 1, 0, 1 )    == "a1b1a2a3a4"
      CHARSORT( "384172852", 1, 1, 0, 0, 4 )  == "134872852"
      CHARSORT( "qwert", .T. )                == "wtrqe"

Compliance

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

Platforms

All

Files

Source is charsort.c, library is ct3.

Seealso

CSETREF()

CharSHR()

CHARSHR()

Process each character in a string with bitwise SHIFT RIGHT operation

Syntax

      CHARSHR( <[@]cString>, <nBitsToSHR> ) --> cSHRString

Arguments

<[@]cString> string to be processed

<nBitsToSHR> number of bit positions to be shifted to the right

Returns

<cSHRString> string with bitwise shifted right characters

Description

The CHARSHR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT RIGHT (SHR) 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. Be aware that bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLR() function instead. 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

      ? charshr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(0)+Chr(0)+Chr(0)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Tests

      charshr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 ) 
      == Chr(0)+Chr(0)+Chr(0)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Compliance

CHARSHR() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

CharSHL()

CHARSHL()

Process each character in a string with bitwise SHIFT LEFT operation

Syntax

      CHARSHL( <[@]cString>, <nBitsToSHL> ) --> cSHLString

Arguments

<[@]cString> string to be processed

<nBitsToSHL> number of bit positions to be shifted to the left

Returns

<cSHLString> string with bitwise shifted left characters

Description

The CHARSHL() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise SHIFT LEFT (SHL) 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. Be aware that bits shifted out of the byte are lost. If you need a bit rotation, use the CHARRLL() function instead. 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

      ? charshl( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(0)+Chr(0)+Chr(0)

Tests

      charshl( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
       == Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128)+Chr(0)+Chr(0)+Chr(0)

Compliance

CHARSHL() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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

CharRLR()

CHARRLR()

Process each character in a string with bitwise ROLL RIGHT operation

Syntax

      CHARRLR( <[@]cString>, <nBitsToRLR> ) --> cRLRString

Arguments

<[@]cString> string to be processed

<nBitsToRLR> number of bit positions to be rolled to the right

Returns

<cRLRString> string with bitwise rolled right characters

Description

The CHARRLR() function constructs a new string from the string passed as parameter. To do this, it performs a bitwise ROLL RIGHT (RLR) 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. Be aware that, in contrast to CHARSHR(), bits rolled out on the right are put in again on the left. 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

      ? charrlr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
      // --> Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Tests

      charrlr( Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)+Chr(32)+Chr(64)+Chr(128), 3 )
       == Chr(32)+Chr(64)+Chr(128)+Chr(1)+Chr(2)+Chr(4)+Chr(8)+Chr(16)

Compliance

CHARRLR() is a new function that is only available in Harbour’s CT3 lib.

Platforms

All

Files

Source is charop.c, library is ct3.

Seealso

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