strings operations, how long is string, changing specific strings

I have a variable "F" where i have 6-7 charcters , now my questions are:
  • 1 how i can cheack how long is this string?
  • 2 now if it have 7 characters then i want to:
  • for characters in position 1-3 if charcter=0 chacnge it into O , and for position 3-7 if charcter=O change it into 0,
  • how can i do that?

 採用された回答

Stephen23
Stephen23 2015 年 1 月 11 日
編集済み: Stephen23 2015 年 1 月 11 日

0 投票

Try this:
F = '000OOOO';
if numel(F)==7
F(1:3) = strrep(F(1:3),'0','O');
F(4:7) = strrep(F(4:7),'O','0');
end
I assumed that you meant your second range to start from 4.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2015 年 1 月 11 日

編集済み:

2015 年 1 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by