使用C ++和mfc进行字符串标记 [英] string tokenizing using C++ and mfc
本文介绍了使用C ++和mfc进行字符串标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请用字符串tokanize帮我。我的输入文件是文本文件,例如
Please help me with string tokanize. my input file is text file such as
1,xyz,1 HP-1 Sigma,1.0,Y,Single,,
2,dfg,32 KES LW0090 ,1.0,Y,Single,,
使用此代码我得到断言 iStart> = 0
且只有一个字符串。(1除外)
with this code I am getting assertion iStart>=0
and only one string.(except 1)
xyz,1 HP-1 Sigma,1.0,Y,Single
这个字符串
我的代码:
this string
my code :
if(File.Open(pathName, CFile::modeRead)) // Open file to be read
{
while(File.ReadString(strLine)) // Read file
{
int Position = 0;
CString Token;
Token = strLine.Tokenize(",", Position);
while(Token!=" ")
{
int total = (int)m_List2.GetItemCount();
for ( int ii=0; ii< total; ii++ )//for row
{
for(int j=0; j<=6;j++) //for columns
{
CString Token=strLine.Tokenize(",",Position);
m_List2.SetItemText(ii,j,Token);
}
}
}
//AfxMessageBox(strMsg, MB_ICONINFORMATION);
// Display resulting contents of strMsg in a message box
}
}
推荐答案
我不同意CString / MFC是个坏主意(但同意它可能被认为是专有的Microsoft)。
CString类内置了一个tokenizer,描述为此处 [ ^ ]。别介意CStringT的东西......它适用于CString。
Joseph Newcomer撰写了一篇关于CString的优秀文章,可以找到这里 [ ^ ],CP版本此处 [ ^ ](这些文章中没有关于标记化的特殊信息)。
I disagree that CString/MFC is a bad idea (but agree that it may be considered "proprietary" Microsoft).
The CString class has a tokenizer built into it, described here[^]. Never mind the "CStringT" stuff ... it applies to CString.
Joseph Newcomer has written an excellent article about CString which can be found here[^], with the CP version here[^] (no special info on tokenizing in these articles).
请参阅我对该问题的评论。使用专有和过时的MFC是一个非常糟糕的主意,特别是对于这样的普遍琐事。
你会从这里得到一个更好的主意: http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7。 html [ ^ ]。
-SA
Please see my comment to the question. Using proprietary and outdated MFC is a really bad idea, especially for such universal chores.
You will get a better idea, for example, from here: http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html[^].
—SA
这篇关于使用C ++和mfc进行字符串标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文