adding single quotation to a string
조회 수: 13 (최근 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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261926/image.jpeg)
![quot.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261926/image.jpeg)
Result.![resultOfMyCommand.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261927/image.jpeg)
![resultOfMyCommand.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261927/image.jpeg)
the right one;
![correctOne.JPG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/261928/image.jpeg)
How can I solve this issue? Thank you.
댓글 수: 0
채택된 답변
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개)
Walter Roberson
2020년 1월 15일
filename = char( extractBetween(filename, "Scans\\", filename(end)) ) ;
Ivan
2021년 1월 29일
sprintf('STRING=''"%s"''','MY STRING')
댓글 수: 2
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 Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!