Replace string with another value
조회 수: 3 (최근 30일)
이전 댓글 표시
What would be a good way replace a full string with first 3 letters of last word. For example '13 Jon Walker' with 'WAL' .
I have about 25 such replacements an this is indeed doable line-by-line "by-hand" using replace function, but that beats the purpose of MATLAB. Plus i might have more in future. I looked up regexprep too but it doesnt quite do that. OR have I missed it ? Is there a way I could apply a 'replace full string with first 3 letters of last word ' rule?
Thank you for your time in advance.
댓글 수: 0
채택된 답변
Walter Roberson
2020년 7월 4일
S = {'13 Jon Walker', '23 skidoo', '0 infinite way blvd'};
upper(regexprep(S, '^.*\s+(...).*', '$1'))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!