Href hyperlink, how to escape double quotes " ?

How can I escape double quotes when displaying a hyperlink in matlab?
Example:
I want to create a hyperlink to execute this command:
[cmd_status cmd_return] = system('explorer.exe /select, "C:\My folder\My file" ')
Without double quotes, the relevant hyperlink is:
disp('<a href="matlab:system(''explorer.exe /select, C:\My folder\My file'');">Click Here</a>')
However, nothing I tried ("", \", '", ...) worked (it has to be double quotes, windows CMD does not accept anything else)
Thank you

2 comentarios

Walter Roberson
Walter Roberson el 20 de Jun. de 2022
Editada: Walter Roberson el 21 de Jun. de 2022
try coding
&quot;
in place of each double quote that is being escaped
I don't this this is working
disp(['<a href="matlab:system(''explorer.exe /select, &quot;C:\My folder\My file&quot;'');">Click Here</a>'])
does not convert the &quot; to ", leaving windows unable to execute the command

Iniciar sesión para comentar.

 Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 20 de Jun. de 2022
Editada: Fangjun Jiang el 21 de Jun. de 2022
knowing
double('"')
ans = 34
char(34)
ans = '"'
This leads to the following, which works out properly
disp('<a href="matlab:system([''explorer.exe /select, '',char(34),''c:\My Folder\My File'',char(34)] );">Click Here</a>')

5 comentarios

covfefe
covfefe el 20 de Jun. de 2022
Editada: covfefe el 20 de Jun. de 2022
This doesn't work. The printed string is:
system('explorer.exe /select,
the href link closes on the double quote " and the rest of the command gets ignored
disp(['<a href="matlab:system(''explorer.exe /select, ', char(34), 'C:\My folder\My file', char(34), ''');">Click Here</a>'])
is no different
(R2018b if that matters)
Fangjun Jiang
Fangjun Jiang el 20 de Jun. de 2022
okay, I see the problem now. It is due to the syntax of the hyperlinks itself using double quote symbol.
Fangjun Jiang
Fangjun Jiang el 21 de Jun. de 2022
A workaround. Creat a m-file function with a full file name in single quotes as input argument, calling system() to open Explorer. Hyperlink to the m-file function.
covfefe
covfefe el 21 de Jun. de 2022
Thanks @Fangjun Jiang. I know this is an option, I was hoping for a cleaner solution. Surely there has to be a way to escape the quotes, right?
Ha! this works out
disp('<a href="matlab:system([''explorer.exe /select, '',char(34),''c:\My Folder\My File'',char(34)] );">Click Here</a>')

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 21 de Jun. de 2022
Editada: Jan el 22 de Jun. de 2022
I'm curious:
% [UNTESTED] [TYPO FIXED]
disp(['<a href="matlab:system(', ...
'strrep(''explorer.exe /select, $C:\My folder\My file$'', ''$'', char(34));">Click Here</a>')
Fanjung's idea:
% [UNTESTED]
disp('<a href="matlab:myExplorer(''C:\My folder\My file'');">Click Here</a>')
function myExplorer(File)
system(sprintf('explorer.exe /select, "%s"');
end

1 comentario

Thanks, this one works too. (there was a typo, correct syntax is:)
disp(['<a href="matlab:system(strrep(''explorer.exe /select, $C:\My folder\My file$'', ''$'', char(34)));">Click Here</a>'])

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Jun. de 2022

Editada:

Jan
el 22 de Jun. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by