xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

CharMix()

Merges the characters of two strings.

Syntax

CharMix( <cString1>, <cString2> ) --> cResult

Arguments

<cString1> and <cString2>
These are two character strings whose characters are merged in the result string.

Return

The function returns a string containing the characters of <cString1> at odd positions and those of <cString1> at even positions. This is useful, for example, to build a SaveScreen() string from a text string and video bytes.

Description

The function operates until all characters of <cString1> are processed. It distinguishes the following situations:

1) Len( <cString1> ) == Len( <cString2> )

  When both input strings are of the same length, each character in <cString1> is followed by the corresponding character in <cString2>.

2) Len( <cString1> ) > Len( <cString2> )

  When the last character of <cString2> is reached, the function starts over with the first character of <cString2>, until the last character of <cString1> is processed.

3) Len( <cString1> ) < Len( <cString2> )

  The function returns when the last character of <cString1> is processed.

Info

See also:CharEven(), CharOdd(), Expand(), ScreenMix()
Category: CT:String manipulation , Character functions
Source:ct\charmix.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example manipulates a savescreen string for changing
// the color periodically until a key is pressed

   PROCEDURE Main
      LOCAL cScreen, cText, cVideo

      CLS
      @ 2,2 SAY "Changing video bytes" COLOR "W+/B"

      cScreen := SaveScreen( 2, 2, 2, 22 )
      cText   := CharOdd( cScreen )
      cVideo  := Chareven( cScreen )

      DO WHILE Inkey(.5) == 0
         cVideo := CharXOR( cVideo, chr(8) )
         cScreen := CharMix( cText, cVideo )
         RestScreen( 2, 2, 2, 22, cScreen )
      ENDDO
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe