How o add apostrophe (') in a char or string array
413 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sultan
am 22 Jun. 2016
Kommentiert: Guillaume
am 22 Jun. 2016
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.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 22 Jun. 2016
Bearbeitet: Stephen23
am 22 Jun. 2016
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 Kommentare
Guillaume
am 22 Jun. 2016
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!