フィルターのクリア

using strrep multiple times

55 ビュー (過去 30 日間)
James Knight
James Knight 2019 年 10 月 18 日
編集済み: Guillaume 2019 年 10 月 18 日
Hi
I want to use strrep multiple times but , whats the correct way of doing this without retyping sstrep
Thanks in advance
choices= strrep(strrep(strrep(usertext, 'left', 'right'), 'up', 'down'), 'black' , 'white');
  3 件のコメント
James Knight
James Knight 2019 年 10 月 18 日
But does that not work only with one singular output?
Thanks
James Knight
James Knight 2019 年 10 月 18 日

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

回答 (2 件)

Guillaume
Guillaume 2019 年 10 月 18 日
Use replace instead:
>> usertext = 'left black left right up down upside white upleft';
>> replace(usertext, {'left', 'up', 'black'}, {'right', 'down', 'white'})
ans =
'right white right right down down downside white downright'

Adam Danz
Adam Danz 2019 年 10 月 18 日
This demo is dedicated to Kazuhisa Hashimoto.
usertext = 'up, up, down, down, left, right, left, right, b, a, start.';
s = regexprep(usertext,{'left','up','b'},{'right','down','a'})
  1 件のコメント
Guillaume
Guillaume 2019 年 10 月 18 日
編集済み: Guillaume 2019 年 10 月 18 日
Should have thought of that usertext for my answer ;)
+1 just for that.
However, be careful that some characters in the regexprep need to be escaped. e.g.
regexprep(usertext, {'.', '+'}, {',', '-'})
will lead to unexpected results. For that reason replace is safer.

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by