Compartir a través de


CRichEditCtrl::LineIndex

Retrieves the character index of a line within this CRichEditCtrl object.

int LineIndex(
   int nLine = -1 
) const;

Parameters

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

Return Value

The character index of the line specified in nLine or –1 if the specified line number is greater then the number of lines in the edit control.

Remarks

The character index is the number of characters from the beginning of the rich edit control to the specified line.

For more information, see EM_LINEINDEX in the Windows SDK.

Example

// The string for replacing.
LPCTSTR lpszmyString = _T("Hello, I'm the new second line.");

int nBegin, nEnd, nIndex;

// Replace the second line, if it exists, of the rich edit control
// with the text lpszmyString.
nIndex = m_myRichEditCtrl.LineIndex(1);
if ((nBegin = nIndex) != -1)
{
   nEnd = nBegin + m_myRichEditCtrl.LineLength(nIndex); 
   m_myRichEditCtrl.SetSel(nBegin, nEnd);
   m_myRichEditCtrl.ReplaceSel(lpszmyString);
}   

Requirements

Header: afxcmn.h

See Also

Concepts

CRichEditCtrl Class

CRichEditCtrl Members

Hierarchy Chart

CRichEditCtrl::LineFromChar

CRichEditCtrl::GetLineCount