gpt4 book ai didi

c++ - 如何检查文本文件中的特定行是否以特定单词开头

转载 作者:搜寻专家 更新时间:2023-10-31 02:13:57 25 4
gpt4 key购买 nike

我有一个文本文件,我将磁盘分区中所有文件的路径写入其中。

WriteToFile::WriteToFile(QString path, QString data)
{
path = "E:/Data.txt";
QFile file(path);
if ( file.open(QFile::Append) )
{
data += "\r\n";
QTextStream stream( &file );
stream << data << endl;
qDebug() << "Writting: " << data;

}
}

我只将新路径写入文件。

void ScanDir::qDirIteratorScanner()
{
// QString basePath;
QDirIterator it(this -> basePath, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext())
{
// QStringList paths;
paths = scanned();
QString path = it.next();

qDebug() << "Collected : " << paths.size();

if (!paths.contains(path)) {
WriteToFile writeToFile(basePath, path);
paths << path;
}
else {
qDebug() << "Already put : " << path;
}
}

}

我预计我有时会开始扫描分区,但在完成扫描分区之前停止程序。我想通过将“LAST-SCAN-POINT”附加到文件 (如果它是新路径) 或最后一个 的最后一个路径条目的开头来标记我上次停止的位置if (!paths.contains(path)) (如果我在检查路径是否已插入文件时终止程序)

如何检查文本文件中以 LAST-SCAN-POINT 开头的行

数据.txt

C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7010.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7011.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7012.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7013.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7014.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7015.idrc
LAST-SCAN-POINT C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7016.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7017.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7018.idrc
C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7019.idrc

最佳答案

如何使用QString::startsWith method ?例如:

QString path = "LAST-SCAN-POINT C:/Program Files/Adobe/Adobe InDesign CC 2015/Plug-Ins/Layout/(Alignment Panel Resources)/idrc_PNGA/7016.idrc";

if(path.startsWith("LAST-SCAN-POINT ")) {

qDebug() << "The path starts with 'LAST-SCAN-POINT '";
} else {
qDebug() << "The path does not start with 'LAST-SCAN-POINT '!";
}

关于c++ - 如何检查文本文件中的特定行是否以特定单词开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40560118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com