xHarbour Reference Documentation > Function Reference |
Determines the position of a single character in a formatted text string or memo field.
MLCToPos( <cString> , ; [<nLineLen>], ; [<nTextRow>], ; [<nTextCol>], ; [<nTabSize>], ; [<lWrap>] , ; [<lLongLines>]) --> nPosition
The function returns the position of the character in <cString> that is located in the text row <nTextRow> and column <nTextCol>. Position counting starts with 1.
MLCToPos() calculates the position of a single character in a formatted text string, based on row and column position. Row and column positions are compatible with the parameters MemoEdit() passes to its user function. The return value of MLCToPos(), in contrast, is compatible with the SubStr() function, so that substrings can be extracted from a formatted character string.
See also: | MemoEdit(), MLCount(), MLPos(), MPosToLC(), SubStr() |
Category: | Character functions , Memo functions |
Source: | rtl\mlcount.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// This example determines the byte position of line 3, column 6 // when the text string is formatted with 10 characters per line: PROCEDURE Main LOCAL cString := "The quick brown fox jumps over the lazy dog" LOCAL cLine := "" LOCAL nLineLen := 10 LOCAL i, imax := MLCount( cString, nLineLen ) ? '"' + cString + '"' ? FOR i:=1 TO imax cLine := MemoLine( cString, nLineLen, i ) ? '"' + cLine + '"' NEXT // Output so far: // "The quick brown fox jumps over the lazy dog" // // "The quick " // "brown fox " // "jumps over" // "the lazy " // "dog " ? i := MLCtoPos( cString, nLineLen, 3, 6, 0) // result: 27 ? SubStr( cString, i, nLineLen ) // result: over the l RETURN
http://www.xHarbour.com