필터 지우기
필터 지우기

How o add apostrophe (') in a char or string array

조회 수: 258 (최근 30일)
Sultan
Sultan 2016년 6월 22일
댓글: Guillaume 2016년 6월 22일
I'm using SIMULINK, in the mask of the block I have created a button that opens a dialog box searches for file using 'uigetfile' in return I get [filename] which is character. I want to display that [filename] as 'filename' with apostrophes in an Edit Box parameter. So that my code can pick 'filename' as string value.

채택된 답변

Stephen23
Stephen23 2016년 6월 22일
편집: Stephen23 2016년 6월 22일
You need to escape the apostrophe by using it twice:
>> '''hello'''
ans = 'hello'
>> sprintf('''%s''','hello')
ans = 'hello'
This is explained in the documentation:
  댓글 수: 2
Sultan
Sultan 2016년 6월 22일
Thanks a lot that worked well. However from your Answer, i also figured this one out
s='''';
strcat(s,'hello',s)
>> 'hello'
typing four times Apostrophe.
Guillaume
Guillaume 2016년 6월 22일
There's mainly only two schools in how you introduce delimiter characters in strings:
  • double the delimiter. This is the way used by matlab, VB, and ?
  • use an escape character (usually \). This is used by pretty much all the other languages, C languages, Java, Python, PHP, etc.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by