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개)

Stephen23
Stephen23 2021년 1월 7일
편집: Stephen23 2021년 1월 7일

0 개 추천

A = 'abc';
B = join(repmat({A},1,3),', ');
B = B{1}
B = 'abc, abc, abc'
C = join(repmat(string(A),1,3),', ') % string output!
C = "abc, abc, abc"
D = sprintf('%1$s, %1$s, %1$s',A)
D = 'abc, abc, abc'

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

질문:

2021년 1월 7일

편집:

2021년 1월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by