开发者

CEdit Text Retrieval in mfc

I am using CEdit with the property of Multiline.My objective is to retrieve the individual line and place it in my CStringArray.

While retrieving the line using GetLine , I have to know the string length of that line.

How to get this?

I tried the function GetLineLength() but that will return the size of the entire line rather than the specified text.

I pasted the code that i have implemented so far:

CEdit m_strMnemonicCode;
CStringArray strMnemonicArray;
LPTSTR temp =  new TCHAR[50];;
int nLineCount = m_strMnemonicCode.GetLineCount();
for(int ni = 0 ; ni < nLineCount ; ni++)
{
    int len = m_strMnemonicCode.LineLength(m_strMnemonicCode.LineIndex(ni));
            //m_strMnemonicCode.GetLine(ni, strText.GetBuffer(len), len);
    m_strMnemonicCode.GetLine( ni 开发者_运维技巧, temp );
    strMnemonicArray.Add(strText);
}


But you need to know the length of the whole line, don't you?
I would not define the buffer as an array of TCHARs, but as a CString, then do GetBuffer() on it.

Check the example in CEdit::GetLineCount

It seems to do more or less what you need.

Edit
I've just written the following test, and it works perfectly for me:

int lc = m_Edit.GetLineCount();    

CString strLine;
CStringArray arr;

for (int i = 0; i < lc ; i++)
{
    int len = m_Edit.LineLength(m_Edit.LineIndex(i));
    m_Edit.GetLine(i, strLine.GetBuffer(len), len);
    strLine.ReleaseBuffer(len);

    arr.Add(strLine);
}

Maybe you are forgetting to add the buffer length to ReleaseBuffer()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜