User-Defined Function to Expand a String

Last reviewed: June 27, 1995
Article ID: Q107610
The information in this article applies to:
  • Microsoft FoxPro for Windows, version 2.5, 2.5a, and 2.5b
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.