xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

MLCToPos()

Determines the position of a single character in a formatted text string or memo field.

Syntax

MLCToPos( <cString>  , ;
         [<nLineLen>], ;
         [<nTextRow>], ;
         [<nTextCol>], ;
         [<nTabSize>], ;
         [<lWrap>]   , ;
         [<lLongLines>]) --> nPosition

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.
<nTextRow>
A numeric value specifying the text row, or line number, to find a character in. Text lines are counted beginning with 1, which is also the default value for <nTextRow>.
<nTextCol>
A numeric value specifying the column within the text row to find a character in. Columns are counted beginning with 0, which is also the default value for <nTextCol>.
<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 scanned 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 scanned.

Return

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.

Description

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.

Info

See also:MemoEdit(), MLCount(), MLPos(), MPosToLC(), SubStr()
Category: Character functions , Memo functions
Source:rtl\mlcount.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

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

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