Share via


CRichEditCtrl::LineFromChar

Retrieves the line number of the line that contains the specified character index.

long LineFromChar(
   long nIndex 
) const;

Parameters

  • nIndex
    Contains the zero-based index value for the desired character in the text of the edit control, or contains –1. If nIndex is –1, it specifies the current line, that is, the line that contains the caret.

Return Value

The zero-based line number of the line containing the character index specified by nIndex. If nIndex is –1, the number of the line that contains the first character of the selection is returned. If there is no selection, the current line number is returned.

Remarks

A character index is the number of characters from the beginning of the rich edit control. For character counting, an OLE item is counted as a single character.

For more information, see EM_EXLINEFROMCHAR in the Windows SDK.

Example

// The index of the char to get information on.
int nIndex = 11;

CString strText;

m_myRichEditCtrl.GetWindowText(strText);
strText = strText.Mid(nIndex, 1);

// Dump the index, character and line number.
TRACE(_T("nIndex = %d, character = %c, line = %d\r\n"),
   nIndex, strText[0], m_myRichEditCtrl.LineFromChar(nIndex));   

Requirements

Header: afxcmn.h

See Also

Reference

CRichEditCtrl Class

Hierarchy Chart

CRichEditCtrl::GetLineCount

CRichEditCtrl::GetLine

CRichEditCtrl::LineIndex

Other Resources

CRichEditCtrl Members