在另一个字符串中插入文件扩展名之前的字符串

Insert string before file extension in another string

本文关键字:字符串 扩展名 插入 另一个 文件      更新时间:2023-10-16

我正在尝试将一个字符串插入另一个字符串,就像你对append()一样,但我想把它放在".xlsx"出现之前,而不是放在最后。

string docName;
docName = "../Toyota Tacoma " + customer.toStdString() + " .xlsx";
if(sold = true){
docName = docName.append("(sold)");
}
doc.CreateDocument(docName);

此代码仅在".xlsx"之后附加"(已售(">

只需稍微重写一下代码,这样您就不必插入:

string docName;
docName = "../Toyota Tacoma " + customer.toStdString();
if(sold == true){
docName += "(sold)";
}
docName += ".xlsx";
doc.CreateDocument(docName);