如何在 MFC 中分离 CString
How to separate a CString in MFC
我有这样的字符串:DialogTitle = IDD_SETTING_DLG
保存在保存文件中(我已经将其存储在名为m_TextArray
的数组中(。
现在我想获取"IDD_SETTING_DLG"
部分(或至少" IDD_SETTING_DLG"
(并将其存储在CString
变量中。我使用了Tokenize
方法,但它不起作用。
这是我的代码:
BOOL CTab1::OnInitDialog()
{
UpdateData();
ReadSaveFile();
SetTabDescription();
UpdateData(FALSE);
return TRUE;
}
void CTab1::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_SHOWDES, m_ShowDes);
}
void CTab1::ReadSaveFile()
{
if (!SaveFile.Open(SFLocation, CFile::modeRead | CFile::shareDenyWrite, &ex))
{
ReadSettingFile();
}
else
{
for (int i = 0; i < 100; i++)
{
SaveFile.ReadString(ReadLine);
m_TextArray[i] = ReadLine.GetString();
}
}
}
void CTab1::SetTabDescription() //m_TextArray[2] is where i stored the text
{
Position = 0;
Seperator = _T("=");
m_ShowDes = m_TextArray[2].Tokenize(Seperator, Position);
while (!m_ShowDes.IsEmpty())
{
// get the next token
m_ShowDes = m_TextArray[2].Tokenize(Seperator, Position);
}
}
任何人的解决方案或提示将不胜感激。
由于您只是在查找字符串中在标记之后出现的部分,因此无需使用 Tokenize
。 只需找到令牌字符的位置(您的" =
"(并获取之后的所有内容:
void CTab1::SetTabDescription() //m_TextArray[2] is where i stored the text
{
CString separator = _T("=");
CString source = m_TextArray[2];
// Get position of token...
int position = source.Find(separator);
// If token is found...
if (position > -1 && source.GetLength() > position)
m_ShowDes = source.Mid(position + 1); // extract everything after token
}
相关文章:
- 在C++中使用Cstring反转字符串
- C++:如何读取分离变量,然后读取向量
- 分离一个静态常量 std::thread?
- .h 和.cpp文件分离时出错,但仅使用 .h 文件时没有错误.我做错了什么?
- 如何在 c++ 中将数据与文件流分离
- 如何转换真实路径 CString c++
- 为什么堆栈和堆在内存中分离得如此之多?
- 具有可分离内核的 2D 模糊卷积
- 为什么即使调用了析构函数,C++11 中的分离线程也可以执行
- __int64 CString 返回错误的值 - C++ MFC
- 如何将 SHFileOperation() 与 CString 路径一起使用
- 在_T值中使用 CString
- 没有大小参数的CString::GetBuffer()做什么
- 防止编译器分离函数的指令
- 如何将 CString 转换为字节 [] 数组?
- 分离库的主机端和 CUDA 设备端版本
- C++将文件行分离为String和Int
- 分离类所有权和使用,生成最佳(快速)代码
- 如何在 MFC 中分离 CString
- 使用cstring.format()中区域设置的小数分离器