# 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"

Status

  Ready

Compliance

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

Platforms

  All

Files

  Source is charswap.c, library is libct.

See Also

- WORDSWAP()
- CSETREF()