Inserting one character many times into a string

I have a string with a bunch of words separated by commas
S='Apples,Oranges,January,February,...'
I get a vector with the placement of all the commas with
commas=strfind(s,',');
how do i place a character before every comma in the string, so it will come out like
Snew='Apples2,Oranges2,January2,February2,...'

 採用された回答

Stephen23
Stephen23 2016 年 12 月 27 日
編集済み: Stephen23 2016 年 12 月 27 日

0 投票

You can simply use strrep:
>> S = 'Apples,Oranges,January,February,...';
>> strrep(S,',','2,')
ans = Apples2,Oranges2,January2,February2,...

その他の回答 (0 件)

カテゴリ

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

質問済み:

2016 年 12 月 27 日

編集済み:

2016 年 12 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by