Exchanges all adjoining characters in a string

     CHARSWAP(<cString>) --> cString


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


     The processed character string is returned.


     CHARSWAP() takes all neighboring characters in <cString> and exchanges
     them.  As a result, bytes in even positions are exchanged for those in
     odd positions.

     CHARSWAP() is very important when you use string integers generated by
     the Clipper I2BIN() function that must be saved or sorted.  The
     CHARSWAP() exchange must be carried out prior to calling CHARSORT()
     (low/high ordering of 16-bit integers) to achieve an accurate result.


     .  Since the length of the character string is not changed, a
        call by reference is recommended.  This increases the speed of the

     .  The value this function returns can be suppressed by setting
        CSETREF() to save working memory space.


     .  Exchange characters that can be displayed:

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

     .  Work with I2BIN:

        ? I2BN(256)                            // 00000000 00000001
        ? I2BIN(1)                             // 00000001 00000000
        ? I2BIN(256) > I2BIN(1)                          // .F.
        ? CHARSWAP(I2BIN(256)) > CHARSWAP(I2BIN(1))      // .T.



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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.