How to converted string with space in double quoted string. For Example: I get string
c:\program files\abc.bat
I want to convert this string to " c:\\program files\\abc.bat
" but only if there is space in the string.
Assuming the STL string s
contains the string you want to check for a space:
if (s.find(' ') != std::string::npos)
{
s = '"' + s + '"';
}
Search for white spaces. If found add \\" to the front and the end of the string. That would be an escaped quotation mark.
std::string str = get_your_input_somehow();
if (str.find(" ") != std::string::npos) {
str = "\"" + str + "\"";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.