how to convert pwd to return / or \\ instead of single back ward slash\

7 ビュー (過去 30 日間)
sri harsha
sri harsha 2020 年 9 月 30 日
回答済み: Walter Roberson 2020 年 9 月 30 日
hello pwd comamnd in windows returns path with single backward \
how to convert it to return either \\ or single forward /
since sprintf requires double backward slash or forward slash in windows

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 9 月 30 日
You are approaching the problem the wrong way. sprintf() only requires \\ or / in the case that the \ appears within the format specification, such as if you had done
result = sprintf(['looking in ', pwd'] )
So... Don't Do That! Pass in the directory specification as a data string to be processed with a %s format:
result = sprintf('looking in %s', pwd)
sprintf() will not process \ in character vectors passed as any argument other than the first.

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by