我正在浏览一个编辑标题的文件文件夹。我正在尝试删除标题的某个部分,但用于在标题中分隔的括号不是标准的 ascii,因此我无法找到删除它的方法。这是标题的示例:【删除此部分】保留此部分。我已经包含了我正在使用的编码。我使用 cstring 来存储标题,然后使用 cstring::find() 来定位该部分,但无法定位该类型的括号。
//sets definition
HANDLE hfind;
WIN32_FIND_DATA data;
//creates string for to search for a specific file
CString FileFormat = FolderPath + Format;
CString NewTitle, PulledFile;
//sets definition for retrieving first file
hfind = FindFirstFile(FileFormat, &data);
//runs loop if handle is good
if (hfind != INVALID_HANDLE_VALUE)
{
//loops until it hits the end of the folder
do {
//adds filename to vector
PulledFile = data.cFileName;
if(PulledFile.Find(L'【') != -1)
{
while (PulledFile.Find(L'】') != -1)
{
PulledFile = PulledFile.Right(PulledFile.GetLength() - 1);
}
}
NewTitle = PulledFile.Left(PulledFile.GetLength()-(Format.GetLength() + 9));
if (sizeof(NewTitle) != NULL)
{
v.push_back(NewTitle);
}
} while (FindNextFile(hfind, &data));
}
最佳答案
您面临的最可能的问题是您没有正确编译。根据 CString documentation :
实际的底层类型取决于您的编译参数。最有可能发生的是,它试图将 Unicode 字符串与您的 MBCS 字符串文字值进行比较,并且不返回任何内容。
如果你想解决这个问题,你应该决定是使用 Unicode 还是 MBCS 并相应地更新你的编译参数,定义 MBCS
或 UNICODE
。
如果使用 Unicode,则必须更改字符串文字,因为它目前适用于 MBCS。您可以使用代码点 L'\u3010'
它将返回正确的字符,或者确保您的文件使用 Unicode 编码并使用 u'【'
。
关于c++ - 如何在c++中读取未包含在ascii中的字符?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34388092/