Exchanges double characters that lie beside each other in a string

     WORDSWAP(<cString>,[<lMode>]) --> cString


     <cString>  [@]  Designates the character string within which the 2-
     byte sequences are exchanged.

     <lMode>  Designates whether the adjoining bytes are exchanged (.T.)
     or not (.F.).  The default value (.F.) designates that the adjoining
     bytes are not exchanged.


     WORDSWAP() returns the modified character string.


     With WORDSWAP(), 2-byte sequences within a character string are
     exchanged for each other.  In this respect the function works exactly
     like CHARSWAP(), except that 16-bit groups are being exchanged.

     The function is used on strings that contain 32-bit integers created by
     the Clipper L2BIN().  The exchange serves as a preparation for a sort
     of these integers using CHARSORT().  In order to achieve a correct sort,
     you must exchange two adjacent bytes (low/high ordering of 16-bit
     integers), in addition to exchanging the 16-bit groups.


     .  When <lMode> is .T., adjoining bytes are only exchanged after
        being exchanged as two 2-byte groups.

     .  The return value of this function can be suppressed by
        implementing CSETREF() to save working memory space.


     .  Exchange characters:

        ? WORDSWAP("1234567890")          // "3412785690"

     .  Also exchange the bytes:

        ? WORDSWAP("1234567890, .T.)      // "4321876590"

     .  Working with L2BIN():

        ? L2BIN(1)               // 00000001 00000000 00000000 00000000
        ? L2BIN(65536)           // 00000010 00000000 00000001 00000000
        ? L2BIN(65536) > L2BIN(1)                                 // .F.
        ? WORDSWAP(L2BIN(65536), .T.) > WORDSWAP(L2BIN(1), .T.)   // .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.