How to convert a string with space to a double quote. For example: I get a string
c:\program files\abc.bat
I want to convert this line to " c:\program files\abc.bat", but only if there is a space in the line.
Assuming the STL sline contains the line you want to check for a space:
s
if (s.find(' ') != std::string::npos) { s = '"' + s + '"'; }
Search for spaces. If it is found, add "forward" and "end of line". This will be a shielded quotation mark.
std::string str = get_your_input_somehow(); if (str.find(" ") != std::string::npos) { str = "\"" + str + "\""; }
Source: https://habr.com/ru/post/1734058/More articles:IPhone Profile Update Help - iphoneCan I use HTTPS certificates for licensing? - c ++NoPrimaryKeyException from DBUnit when loading a dataset into a database - javaIs the role of business intelligence redundant in real-life Agile projects? - agileHow can I fix the "-e aborted due to compilation errors" in the Makefile module of the Perl module? - perlAre there any problems with Ruby priority using Proc.call vs. Proc. []? - ruby | fooobar.comUsing variables as a value, not as a reference - variablesRedirect with login.jsp if it is already registered - redirectWhy is my conversion from C # to VB not working? - c #Problem with SQL server smalldatetime insert query - sql-serverAll Articles