adding single quotation to a string

16 ビュー (過去 30 日間)
MoHa
MoHa 2020 年 1 月 15 日
コメント済み: Ivan 2021 年 1 月 30 日
Hi everybody,
my code accept just this format of String --> filename='"GComScan_20200115_135716.sdb"' (first and last Quotes are single) why i dont know ?
i have tried with this command to get that, but the result was reverse, means first and last Quotes are dobble " ' ' " (without space).
filename = "'" + string(extractBetween(filename, "Scans\\", filename(end)))+ "'"quot.JPG
Result.resultOfMyCommand.JPG
the right one;
correctOne.JPG
How can I solve this issue? Thank you.

採用された回答

Adam Danz
Adam Danz 2020 年 1 月 15 日
編集済み: Adam Danz 2020 年 1 月 15 日
filename = sprintf('"%s"',string(extractBetween(filename, "Scans\\", filename(end))));
Result:
filename2 = '"GComScan_20200115_135716.sd"'
Explanation:
filename is actually a character array, not a string (see Characters & Strings to understand the difference). The double quotes are part of the character vector. The outer single quotes are not part of the character vector; they actually define the variable as a character vector.
To see the actual content of the filename variable,
>> disp(filename)
"GComScan_20200115_135716.sd"
  2 件のコメント
MoHa
MoHa 2020 年 1 月 15 日
Thank you Adam for the Solution and Explanation.
Adam Danz
Adam Danz 2020 年 1 月 15 日
Glad I could help!

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 1 月 15 日
filename = char( extractBetween(filename, "Scans\\", filename(end)) ) ;
  1 件のコメント
MoHa
MoHa 2020 年 1 月 15 日
Thanks Walter for your feedback.

サインインしてコメントする。


Ivan
Ivan 2021 年 1 月 29 日
sprintf('STRING=''"%s"''','MY STRING')
  2 件のコメント
Adam Danz
Adam Danz 2021 年 1 月 29 日
編集済み: Adam Danz 2021 年 1 月 29 日
@Ivan I'm not sure how this addresses the question.
Anyway, I saw your profile image in Tomsk, I've been to Tomsk in July 2010 for a conference and spent a week there, met a lot of great people I'm still in touch with.
Ivan
Ivan 2021 年 1 月 30 日
@Adam Danz sorry, yes, wrong answer, seems it was for another question, too much opened tabs in the browser.
Thats surprise, you've been in Tomsk, nice old city with a lot of students. I also have been there for a week, have made seminars for students, control systems with MATLAB. Amazing world.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by