CharMix Function | |
Return a string whose odd-numbered characters and even-numbered characters are from 2 different strings.
Namespace:
XSharp.Core
Assembly:
XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax FUNCTION CharMix(
cOdd AS STRING,
cEven AS STRING
) AS STRING
public static string CharMix(
string cOdd,
string cEven
)
Request Example
View SourceParameters
- cOdd
- Type: String
The string whose characters will constitute the odd-numbered characters in the returned string. - cEven
- Type: String
The string whose characters will constitute the even-numbered characters in the returned string.
Return Value
Type:
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.
Remarks
CharMix() provides a convenient way to recombine strings extracted from CharOdd() and CharEven().
Examples
This example mixes 2 strings:
1? CharMix("13579", "24680")
This example shuffles the cards in a game:
1Function Start()
2 LOCAL cPoker AS STRING
3 cPoker := "AKJQ0123456789"
4 ? Shuffle(cPoker, 10)
5 RETURN TRUE
6FUNCTION Shuffle(cDeck AS STRING, ;
7 siShuffles AS SHORTINT) AS STRING PASCAL
8
9
10 LOCAL siCounter AS SHORTINT
11 LOCAL siCards AS SHORTINT
12 siCards := SLen(cDeck)
13
14
15 siCards += 2
16 cDeck := PadC(cDeck, siCards)
17 FOR siCounter := 1 UPTO siShuffles
18
19 cDeck := CharMix(Substr3(cDeck, 1,;
20 siCards/2), Substr2(cDeck, (siCards/2)+1))
21 NEXT
22 RETURN Substr3(cDeck, 2, siCards-2)
23
See Also