Repeat a string with a delimiter
显示 更早的评论
Assuming a string
A = 'abc';
How to repeat it for several times, say 3 times, with a delimiter ',', so that to obtain:
'abc, abc, abc'
Is there a neat solution to do so?
回答(1 个)
A = 'abc';
B = join(repmat({A},1,3),', ');
B = B{1}
C = join(repmat(string(A),1,3),', ') % string output!
D = sprintf('%1$s, %1$s, %1$s',A)
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!