What is the purpose of using 2 single quotes ?

조회 수: 3 (최근 30일)
Muhammet
Muhammet 2013년 7월 29일
Hi everyone,here is my question that I dont understand why 2 single quotes is used in code below.
set(1,'HandleVisibility','callback');
set(2,'ButtonDownFcn','get(0,''Children'')');
% Note that Children is surrounded by 2 single quotes.
or here :
h=figure;
set(h,createFcn,display(‘’Cloning a figure’’));
copyobj(h,0);

채택된 답변

Jan
Jan 2013년 7월 29일
편집: Jan 2013년 7월 29일
Two single quotes create one single quote inside strings. So the following expressions create the same output:
s1 = 'This is called ''string''.'
s2 = ['This is called ', char(39), 'string', char(39), '.']
isequal(s1, s2) % TRUE
The benefits of the double quotes are obvious, but it gets confusing, when the number of quotes grow:
s3 = 'This is is an empty string: ''''';
  댓글 수: 2
Muhammet
Muhammet 2013년 7월 29일
편집: Muhammet 2013년 7월 29일
Thank you but this is not answer.Because I know form other programmin languages this is kind of escape sequence but for my case not.Because the message shown in command window is : Cloning Figure , not 'Cloning Figure' . You can test it.And also if I try to remove outer quotes it is giving error.
Jan
Jan 2013년 7월 29일
편집: Jan 2013년 7월 29일
In your 2nd example you use accents, not simple quotes. This is not valid in Matlab.
In your original question you do not mention a message at all. Please do not conceal such important information, when you ask a question. Adding this later as comment only wastes your time and the time of your helpers. Thanks.
Now please explain exactly again, what appears where and what you expect instead.
If you want to write a string containing quotes and hide this in callback defined as string, follow the instructions I gave already: While the two quotes appear as single quote, you require 4 quotes to insert two quotes which are displayed as 1 quote. I mentioned already, that this is confusing. Better use function handles instead to avoid such nested quote stuff. Finally I'm still convinced, that my message is an answer to your question: "What is the purpose of using 2 single quotes ?"

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by