列表Ctrl& CString :: Tokenize [英] ListCtrl & CString::Tokenize

查看:76
本文介绍了列表Ctrl& CString :: Tokenize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从文本文件中读取数据.我正在使用CString标记化来检测"\ t"
但是每当我运行代码时,它就会给我断言失败错误.另外,在我注释掉标记化功能并使用常规功能后,我似乎无法在第二列中添加文本.这就是我在Oninit中调用函数的方式:
"ReadConfigFile();"

Hi, I''m reading data from a text file. and I''m using CString tokenize to detect "\t"
But whenever i run the code, it gives me an Assertion Fail error. Also, after i comment off the tokenize function and use the normal function, I cannot seem to add in text in the 2nd Column onwards. This is how i call the function in Oninit:
"ReadConfigFile();"

void CGraphicPlotter1Dlg::ReadConfigFile()
{
	CString sBuf;
	meStringArray ArrLine;
	int foundAt = ArrLine.Find(searchStr);
	int endAt = ArrLine.Find(searchStr);
	int unitAt;
	int unitEnd;
	int i;
	int imgNbr = 0;

	CString Seperator = _T("\t");
	int Position = 0;
	CString Token;

	ReadFile("New Text Document.txt", ArrLine);
	int dwLength = ArrLine.GetSize();
	searchStr = "UnitY-Name";
	foundAt = ArrLine.Find(searchStr);
			
	if(foundAt != -1 )
	{	
		i = foundAt + 1;
		while( i < dwLength)
			{
				// Get Name of curves
				sBuf=ArrLine.GetAt(i);
				endAt = sBuf.Find("\t");
				resultStr = sBuf.Mid(0,endAt);
				LPSTR curveName = resultStr.GetBuffer(); // Convert from CString to LPSTR

				//Token = sBuf.Tokenize(Seperator, Position);
				//while(!Token.IsEmpty())
				//{
					// Get next token.
					//Token = sBuf.Tokenize(Seperator, Position);
				//} 

				// Get Units of curves
				unitAt = sBuf.Find(" ");
				unitEnd = sBuf.Find("\t",23);
				nextStr = sBuf.Mid(unitEnd,unitAt);

				lvItem.mask = LVIF_IMAGE |  LVIF_TEXT;

				// Insert data into ListCtrl
				lvItem.mask = LVIF_IMAGE |  LVIF_TEXT;
				lvItem.iItem = imgNbr;
				lvItem.iSubItem = 0;
				lvItem.pszText = curveName;
				lvItem.iImage = imgNbr;
				nItem = this->m_listTable.InsertItem(&lvItem);
				this->m_listTable.SetItemText(nItem, 1, nextStr);
				//this->m_listTable.SetItemText(nItem, 2, nextStr);
				//this->m_listTable.SetItemText(nItem, 3, nextStr);
				i++;
				imgNbr++;	
			}
		}
		else
		{
			AfxMessageBox("No Curves Found!", MB_ICONEXCLAMATION);
		}	
}



任何帮助将不胜感激.



Any help will be greatly appreciated.

推荐答案

我认为您需要通过使用InsertColumn
i think you need insert more Column by using InsertColumn


if sBuf.Find( "\ t")失败,返回-1.
那么sBuf.Mid(0,endAt)可能会导致断言错误
if sBuf.Find("\t") fail ,it returns -1.
then sBuf.Mid(0,endAt)may cause a assertion error


我已经解决了这个问题.我在错误的位置初始化了位置".这就是为什么它不断给我调试断言错误的原因.
I''ve solved this. I initialized the "Position" at the wrong location. That''s why it keeps giving me the debug assert error.


这篇关于列表Ctrl&amp; CString :: Tokenize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆