CEdit::LineIndex

Call this function to retrieve the character index of a line within a multiple-line edit control.

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 than the number of lines in the edit control.

Remarks

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

This member function is only processed by multiple-line edit controls.

For more information, see EM_LINEINDEX in the Windows SDK.

Example

// The string for replacing.
CString strString(_T("Hi, we're the replacements."));
int nBegin, nEnd;

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

Requirements

Header: afxwin.h

See Also

Concepts

CEdit Class

CEdit Members

Hierarchy Chart

CEdit::LineFromChar