1.

Solve : check for double quote in a string?

Answer» <html><body><p>Is it <a href="https://interviewquestions.tuteehub.com/tag/possible-592355" style="font-weight:bold;" target="_blank" title="Click to know more about POSSIBLE">POSSIBLE</a> to check for a double quote at the <a href="https://interviewquestions.tuteehub.com/tag/end-239295" style="font-weight:bold;" target="_blank" title="Click to know more about END">END</a> of a string?<br/><br/>Reason is, I've created a batch file where users drag and <a href="https://interviewquestions.tuteehub.com/tag/drop-244477" style="font-weight:bold;" target="_blank" title="Click to know more about DROP">DROP</a> a folder onto the batch file and it uses that as a parameter.<br/><br/>If the folder has a space it encloses it in double quotes, I can strip them off with the SET <a href="https://interviewquestions.tuteehub.com/tag/command-11508" style="font-weight:bold;" target="_blank" title="Click to know more about COMMAND">COMMAND</a>...but if there is no space then it doesn't enclose it in quotes.<br/><br/> Code: <a>[Select]</a>set StartFolder=%1<br/>if '%StartFolder%==' goto NoFolder<br/>set tmpstr=%StartFolder:~-1%<br/><br/>rem *** If last char is double quote, strip them off - '" = Single the double quote***<br/>if '%tmpstr% == '" set StartFolder=%StartFolder:~1,-1%<br/><br/>set tmpstr=%StartFolder:~-1%<br/>rem *** If last char is not backslash, <a href="https://interviewquestions.tuteehub.com/tag/add-361838" style="font-weight:bold;" target="_blank" title="Click to know more about ADD">ADD</a> one ***<br/>if '%tmpstr% NEQ '\ set StartFolder=%StartFolder%\<br/><br/><br/>How can I check if the parameter has quotes?Solved it by adding a ^ before the double quote...<br/><br/> Code: <a>[Select]</a>set StartFolder=%1<br/>if '%StartFolder%==' goto NoFolder<br/>set tmpstr=%StartFolder:~-1%<br/><br/>rem *** If last char is double quote, strip them off - '" = Single the double quote***<br/>if '^%tmpstr% == '^" set StartFolder=%StartFolder:~1,-1%<br/><br/>set tmpstr=%StartFolder:~-1%<br/>rem *** If last char is not backslash, add one ***<br/>if '%tmpstr% NEQ '\ set StartFolder=%StartFolder%\<br/> You do know that the tilde variable modifier strips off any surrounding quotes from parameter strings? <br/><br/>If %1 is a passed parameter string, then %~1 is that same string but without any surrounding double quotes. (If no quotes are present then %1 and %~1 are identical)<br/><br/>For full details of variable modifiers see the FOR documentation e.g. by typing FOR /? at the prompt.<br/><br/><br/><br/><br/></p></body></html>


Discussion

No Comment Found