我有以下Qstring
"diskinfo": "Node: ASHUTOSH-PC, Description: Local Fixed Disk, FreeSpace: 420842713088, Name: C:, Size : 499875049472 Node: ASHUTOSH-PC, Description: CD-ROM Disc, FreeSpace: , Name: D:, Size : Node: ASHUTOSH-PC, Description: Local Fixed Disk, FreeSpace: 324858568704, Name: E:, Size : 487687450624 Node: ASHUTOSH-PC, Description: CD-ROM Disc, FreeSpace: 0, Name: F:, Size : 553459712",
我需要以下输出
{
"diskinfo": "Node: ASHUTOSH-PC, Description: Local Fixed Disk, FreeSpace: 420842713088, Name: C:, Size : 499875049472
Node: ASHUTOSH-PC, Description: CD-ROM Disc, FreeSpace: , Name: D:, Size :
Node: ASHUTOSH-PC, Description: Local Fixed Disk, FreeSpace: 324858568704, Name: E:, Size : 487687450624
Node: ASHUTOSH-PC, Description: CD-ROM Disc, FreeSpace: 0, Name: F:, Size : 553459712",
}
这怎么可能?在Qt
以下是我获取Qstring的代码
QString WctUtils::getDiskSpace( )
{
static QString diskSpaceCmd ( qgetenv("WINDIR")
+ "\\system32\\wbem\\wmic logicaldisk get name, freespace, size, description /format:csv");
QProcess proc;
QByteArray qba;
QString out_str;
proc.start(diskSpaceCmd);
if(proc.waitForFinished(-1))
{
qba = proc.readAllStandardOutput();
qba = qba.trimmed();
qba =qba.replace('\r',' ');
QString myString =qba;
QStringList myStringList = myString.split("\n");
QStringList descriptions = myStringList[0].split(",");
for(int index = 1;index < myStringList.length();index++)
{
QStringList data = myStringList[index].split(",");
QStringList out;
for(int ind_2 = 0; ind_2 < data.length(); ind_2++)
out.push_back(descriptions[ind_2] + ": " +data[ind_2]);
out_str += out.join(", ");
}
}
QString diskSpace(out_str);
return (diskSpace);
}
如何使用word&#39; node&#39;来追加字符串。在qt c ++的新行?
答案 0 :(得分:0)
我会在单词&#34; Node:&#34;上拆分,然后因为拆分会删除你要拆分的内容,在结果中预先发送&#34;节点:&#34 ;回到每个字符串。你可以通过以下方式做到:
for (int index = 1; index < myStringList.length(); index++)
{
myStringList[index] = "Node:" + myStringList[index];
}