CARVIEW |
Select Language
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 01 Sep 2025 00:52:16 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: vis31=00045ce868b4ee40; path=/
Last-Modified: Tue, 17 Dec 2024 16:25:17 GMT
Content-Encoding: gzip
Removing double quotes from Cstring - C++ Forum
Removing double quotes from Cstring
Hi, sorry its late...
I am trying to do a few things with strings.
- 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.
Here is part of my code
I am trying to do a few things with strings.
- 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.
Here is part of my code
|
|
Last edited on
Why use CString and char arrays and not std::string?
Perhaps sample input(s) and expected output would make it clear what's required.
Perhaps sample input(s) and expected output would make it clear what's required.
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
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
|
|
Last edited on
Since C++20 you can do this for L4:
You can also do this:
|
|
You can also do this:
|
|
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
https://en.cppreference.com/w/cpp/filesystem/path
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.
& < > [ ] | { } ^ = ; ! ' + , ` ~
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.https://en.cppreference.com/w/cpp/filesystem/path
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.
Thanks for your advice.
I myself don't get the double quotes even pressing TAB. This user even took a video showing the quotes.
I myself don't get the double quotes even pressing TAB. This user even took a video showing the quotes.
You only get double quotes if some component of the filename path has a special character in it.
Topic archived. No new replies allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3
Spotted an error? contact us