Viva Clipper !

Strings as array

Advertisements
/*
StrAsArr.prg
Harbour offers a very handy string manipulation method: 
strings can be processed by indexing as array.
This sample inverts a string while converting it to uppercase.
lib is xHB, so you need add xHB lib calling in the your 
compile command:
hbmk2 -lxHB StrAsArr -run
*/
#include "xhb.ch"
PROCEDURE Main()

 CLS
cString := "This is a string"
? cString
?
FOR n1Char := LEN( cString ) TO 1 STEP -1
   cString[ n1Char ] := UPPER( cString[ n1Char ] )
   ?? cString[ n1Char ]
NEXT 

 /* Result: 

 This is a string
 GNIRTS A SI SIHT 

 */

 @ MAXROW(), 0
 WAIT "EOF StrAsArr.prg"

RETURN // StrAsArr.Main()

Advertisements

Advertisements