Return a string whose odd-numbered characters and even-numbered characters are from 2 different strings.
XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax View Source
cOdd AS STRING,
cEven AS STRING
) AS STRING
public static string CharMix(
- Type: String
The string whose characters will constitute the odd-numbered characters in the returned string.
- Type: String
The string whose characters will constitute the even-numbered characters in the returned string.
A string in which characters from <cOdd> and <cEven> appear alternately. The length of <cOdd> determines the length of the returned string: the length is twice the length of <cOdd>, assuming that <cEven> contains at least one character:
A longer <cEven> string is cut down to the length of <cOdd>.
A shorter <cEven> is processed from beginning to end, wrapping to the beginning again until there are no more characters in <cOdd>.
If <cEven> contains less than one character, a NULL_STRING is returned.
CharMix() provides a convenient way to recombine strings extracted from CharOdd() and CharEven().
This example mixes 2 strings:
? CharMix("13579", "24680") // 1234567890
This example shuffles the cards in a game:
LOCAL cPoker AS STRING
cPoker := "AKJQ0123456789"
? Shuffle(cPoker, 10) // Q37A048K159J26
FUNCTION Shuffle(cDeck AS STRING, ;
siShuffles AS SHORTINT) AS STRING PASCAL
// Assumes even number of cards.
// Length of cDeck is divisible by 2
LOCAL siCounter AS SHORTINT
LOCAL siCards AS SHORTINT
siCards := SLen(cDeck)
// First and last cards are not shuffled;
// so add/pad blank cards
siCards += 2
cDeck := PadC(cDeck, siCards)
FOR siCounter := 1 UPTO siShuffles
// Cut the deck in half and shuffle
cDeck := CharMix(Substr3(cDeck, 1,;
siCards/2), Substr2(cDeck, (siCards/2)+1))
RETURN Substr3(cDeck, 2, siCards-2)
// Exclude added blank cards