filesep for window '\', which may cause sprintf doesn't work for some '\%d' string, how can i avoid ?

4 ビュー (過去 30 日間)
Huang Chi-En
Huang Chi-En 2020 年 7 月 2 日
回答済み: Robert U 2020 年 7 月 2 日
str = " \num_%d " ;
result = sprintf(str, 1) ;
the above example can not output : " \num_1 " normally.
When I use the filesep global var of matlab in window, ' \ ' will come out, which cause the sprintf dosen't work.
How can I avoid the above situation without changing the function of sprintf ?

回答 (1 件)

Robert U
Robert U 2020 年 7 月 2 日
Hi Huang Chi-En,
please refer to sprintf-documentation; special characters might need different syntax. Since backslash is an escape character, you would have to use "\\" instead:
str = " \\num_%d ";
result = sprintf(str, 1);
Kind regards,
Robert

カテゴリ

Help Center および File ExchangeFile Name Construction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by