- I need to remove double quotes from a users input
- Then the string needs to be divide into two separate strings. So that I have a folder path and a complete file path.
seeplus thanks for your suggestion, I am now using an std::string.
The following will remove the double " quotes from a string and finds the file path without the file name. for example C:\\path_of_file\\ instead of C:\\path_of_file\\file.bin
If the user is using double-quotes, it is because he was pressing TAB to get auto-complete at the command line, which presumably added the double-quotes to the filename because the file name contains one or more of the following special characters and/or any whitespace:
& < > [ ] | { } ^ = ; ! ' + , ` ~
Filenames themselves are not supposed to contain double-quotes. (There are very tricky ways around that, but I think it unlikely to appear in your valid input. Windows itself won’t know how to handle such a filename.)
The best way to handle this is to use a std::filesystem::path object. Assign it the (possibly quoted) filename. You will get a correct result when you use the path to open the file. You also get a slew of convenient functions to split the path into directory and filename. As always, the documentation is your friend.
I do NOT recommend trying to parse any of this yourself, either using std::quoted or messing with searching for path separatorS. Let the path object do all that for you. It will get it correct where stuff we try to hack up will fail when you least expect it.