| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Calculates row and column position of a character in a formatted string or memo field.
MPosToLC( <cString> , ;
[<nLineLen>], ;
[<nCharPos>], ;
[<nTabSize>], ;
[<lWrap>] , ;
[<lLongLines>]) --> { nTextRow, nTextCol }
The function returns an array of two elements. The first element contains the row in the text where the character at position <nCharPos> is located, and the second element is the column number.
MPosToLC() calculates the row and column position of a single character in a formatted text string, based on its byte position. Row and column positions are compatible with the parameters MemoEdit() passes to its user function. That is, rownumbersing begins with 1 and columns are numbered beginning with 0.
| See also: | MemoEdit(), MLCToPos(), MLPos() |
| Category: | Character functions , Memo functions |
| Source: | rtl\mpostolc.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// This example determines the text row and column of the character
// at position 36, when the text is formatted with 10 characters per line:
PROCEDURE Main
LOCAL cString := "The quick brown fox jumps over the lazy dog"
LOCAL aLines := {}
LOCAL nLineLen := 10
LOCAL i, imax := MLCount( cString, nLineLen )
LOCAL aRowCol
? '"' + cString + '"'
?
FOR i:=1 TO imax
AAdd( aLines, MemoLine( cString, nLineLen, i ) )
? '"' + aLines[i] + '"'
NEXT
// Output so far:
// "The quick brown fox jumps over the lazy dog"
//
// "The quick "
// "brown fox "
// "jumps over"
// "the lazy "
// "dog "
? SubStr( cString, 36 ) // result: lazy dog
aRowCol := MPosToLC( cString, nLineLen, 36 )
? aRowCol[1], aRowCol[2] // result: 4 4
? SubStr( aLines[aRowCol[1]], 1+aRowCol[2] ) // result: lazy
RETURN
http://www.xHarbour.com