Flipping specific segment of string rather than the whole string
조회 수: 1 (최근 30일)
이전 댓글 표시
If I have a string
str='One two buckle my shoe'
how can I flip it to look as follows?
strM='enO owt elkcub ym eohs'
I have tried using 'flip' and 'reverse' in a few different ways but every time I get
strN='eohs ym elkcub owt enO'
댓글 수: 2
Jan
2019년 1월 17일
This sounds like a homework question. Please mention this explicitly, because then we can help you to solve the problem by your own. This is better than submitting a solution written by someone else.
답변 (3개)
madhan ravi
2019년 1월 17일
편집: madhan ravi
2019년 1월 17일
str='One two buckle my shoe';
b=strsplit(str,' ');
strM=strjoin(cellfun(@flip,b,'un',0))
b=flip(strsplit(str,' '));
strN=strjoin(cellfun(@flip,b,'un',0))
Gives:
str =
'One two buckle my shoe'
strM =
'enO owt elkcub ym eohs'
strN =
'eohs ym elkcub owt enO'
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!