| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Extracts a line of text from a formatted character string or memo field.
MemoLine( <cString> , ;
[<nLineLen>] , ;
[<nLineNum>] , ;
[<nTabSize>] , ;
[<lWrap>] , ;
[<lLongLines>], ;
[@<nOffSet>] ) --> cTextLine
The function returns a character string of <nLineLen> characters. If <lWrap> is .T. (true) and the extracted line does not end with a complete word, the line is filled with blank spaces up to the length of <nLineLen>. If <lWrap> is .F. (false), the returned string contains <nLineLen> characters and a next call to MemoLine() extracts characters following the next hard carriage return.
If <nLineNum> is larger than the number of lines contained in <cString>, an empty string ("") is returned.
MemoLine() is used to extract single text lines from a formatted text string that may include Tab characters (Chr(9)), Soft carriage returns (Chr(141)) or Hard carriage returns (Chr(13)). Multiple lines are usually extracted within a FOR..NEXT loop whose upper boundary is determined by the total number of text lines in a string, as reported by function MLCount().
If multiple lines are extracted, it is strongly recommended to pass <nOffSet> by reference to MemoLine(), initializing the parameter with 1. This improves the speed of text extraction considerably.
note: when text lines extracted with MemoLine() are displayed, they have only the same length if a fixed-size font is used for display.
| See also: | FLineCount(), HB_FReadLine(), HB_ReadLine(), MemoEdit(), MemoRead(), MemoWrit(), MLCount(), MLPos() |
| Category: | Character functions , Memo functions |
| Source: | rtl\txtline.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates MemoLine() usage for extracting all lines
// of a text file. The difference of using line numbers versus using
// line offsets is outlined.
PROCEDURE Main( cFileName )
LOCAL nLineLen := 60
LOCAL nTabSize := 8
LOCAL lWrap := .T.
LOCAL i, imax, cText, cLine, nOffSet, nTextLen
LOCAL t1, t2, t3
IF Empty( cFileName ) .OR. .NOT. File( cFileName )
? "No file specified"
QUIT
ENDIF
cText := MemoRead( cFileName )
t1 := Seconds()
imax := MLCount( cText, nLineLen, nTabSize, lWrap )
FOR i:=1 TO imax
cLine := MemoLine( cText, nLineLen, i, nTabSize, lWrap )
NEXT
t2 := Seconds()
// This example shows the use of the <nOffSet> parameter.
// Note that the line number does not change, but the starting
// position in the text to begin extracting a line
nTextLen := Len( cText )
nOffSet := 1
i := 0
DO WHILE nOffSet <= nTextLen
cLine := MemoLine( cText, nLineLen, 1, nTabSize, lWrap,, @nOffSet )
i++
ENDDO
t3 := Seconds()
? "Using line number:", t2-t1, "secs (" + Ltrim(Str(imax)) + " lines)"
? "Using line offset:", t3-t2, "secs (" + Ltrim(Str(i)) + " lines)"
RETURN
http://www.xHarbour.com