xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

MPosToLC()

Calculates row and column position of a character in a formatted string or memo field.

Syntax

MPosToLC( <cString>  , ;
         [<nLineLen>], ;
         [<nCharPos>], ;
         [<nTabSize>], ;
         [<lWrap>]   , ;
         [<lLongLines>]) --> { nTextRow, nTextCol }

Arguments

<cString>
A character string or memo field to scan. It can be a formatted text string that includes Tab and Hard/Soft carriage return characters.
<nLineLen>
A numeric value specifying the number of characters per text line. It is usually a value between 4 and 254. If <nLineLen> is larger than 254 characters, parameter <lLongLines> must be set to .T. (true). The default value for <nLineLen> is 79.
<nCharPos>
A numeric value indicating the position of the character in <cString>. The default value is 1.
<nTabSize>
A numeric value specifying the number of blank spaces the Tab character should be expanded to. It defaults to 4 blank spaces.
<lWrap>
A logical value indicating if word wrapping should be applied to <cString> when lines are scanned. The default value is .T. (true), resulting in text lines that contain whole words only. When a word does not fit entirely to the end of the extracted text line, it is wrapped to the next text line. Passing .F. (false) for this parameter turns word wrapping off so that only lines ending with a hard carriage return are scanned.
<lLongLines>
This parameter defaults to .F. (false). It must be set to .T. (true) when text lines of more than 254 characters should be extracted.

Return

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.

Description

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.

Info

See also:MemoEdit(), MLCToPos(), MLPos()
Category: Character functions , Memo functions
Source:rtl\mpostolc.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe