Function MemoLine() Foundation

Extracts text lines from a character string or from a memo field.

MemoLine( <cString>   , ;
         [<nLineLen>] , ;
         [<nLine>]    , ;
         [<nTabSize>] , ;
         [<lWrap>]      ) --> cLine
<cString> is a character string or the contents of a memo field from which a text line is extracted.
<nLineLen> is a positive integer value specifying the maximum line length for <cString>. The default is 79 characters per line.
<nLine> specifies the position of the line to extract within the text. By default the first line in the text is extracted.
<nTabSize> indicates the tab size. The default value is 4 characters per tab. The tab can accept a maximum value of <nLineLen> - 1.
The logical value <lWrap> specifies whether automatic word wrapping is taken into consideration when retrieving the line of text. The default value is .T. (true). When the value .F. (false) is specified, word wrap is not taken into consideration.

MemoLine() extracts the line specified with <nLine> from the text <cString>. When the extracted string is shorter than <nLineLen> the character string is padded with blank spaces to the length <nLineLen>. When <nLine> contains a value which is greater than the entire number of lines in <cString>, a null string ("") is returned. If automatic word wrap is taken into consideration (by specifying .T. for <lWrap>), the last word in a line is treated as moved to the next line if it does not fit completely in the extracted line. If <lWrap> contains the value .F., entire lines are always extracted up to a hard return (Chr(13)+Chr(10)) and the first <nLineLen> characters are returned.


The memo function MemoLine() extracts character strings from text. It is comparable to the function SubStr(), but works on the basis of entire lines. MemoLine() is often used with the memo function MlCount() which determines the total number of lines in the text. MemoLine() returns a text line without formatting characters like tab (Chr(9)) and return (Chr(13)+Chr(10)).


// In the example, a file is read and the individual lines 
// in the file are written to an array. This might be used 
// to process configuration files in an Xbase++ program. 

FUNCTION ReadSysData( cSysFilename ) 
   LOCAL cText     := MemoRead( cSysFilename ) 
   LOCAL nMaxLines := MlCount( cText, 80 ) 
   LOCAL aLines[ nMaxLines ], n 

   FOR n:=1 TO nMaxLines 
      aLines[ n ] := Trim( MemoLine( cText, 80, n ) ) 

RETURN aLines 

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.