GTA.sprx
GTA.sprx

Reputation: 827

Insert string before file extension in another string

I'm trying to insert a string into another string like you would with append() but rather than at the end I'd like to put it before the occurrence of ".xlsx".

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

This code just appends "(sold)" after ".xlsx"

Upvotes: 1

Views: 233

Answers (1)

Stephan Lechner
Stephan Lechner

Reputation: 35154

Simply rewrite the code a bit, such that you do not have to insert at all:

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

Upvotes: 5

Related Questions