Strings as array

/*
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()

StrAsArr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.