User-Defined Function to Expand a String

ID: Q107610

The information in this article applies to:

SUMMARY

The user-defined function (UDF) below inserts a space between each character of the passed variable by using a substring function inside a DO loop.

MORE INFORMATION

Create a program file with the following code:

   CLEAR
   SET TALK   OFF
   SET CURSOR OFF
   Title    = "SEE IT GROW"
   NewTitle = EXPAND(TITLE)
   @ 10,10 SAY NewTitle
   RETURN

   ******************************************************************
   * Function..: EXPAND
   * Notes.....: This function inserts blanks after each character in
   *             a string.
   *
   * Parameters: TheString - The expression to convert.
   *
   ******************************************************************
   FUNCTION  Expand
   PARAMETER TheString
   STORE LEN(TheString) TO Mlen
   STORE 1              TO Mcount
   STORE SPACE(1)       TO NewString
   DO WHILE Mcount <= Mlen
      NewString = NewString + SUBSTR(TheString,Mcount,1) + " "
      Mcount    = Mcount + 1
   ENDDO
   RETURN (LTRIM(NewString))

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b string KBCategory: kbprg kbcode KBSubcategory: FxprgGeneral

Last Reviewed: June 27, 1995