How to say remove "-1" from the end of a string if exists?

조회 수: 1 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020년 1월 29일
답변: Guillaume 2020년 1월 29일
I have array of strings that some of them have "-1" at the end. Like "sectioned-1".
How can I get rid of "-1" from the end of thos strings?

답변 (2개)

Guillaume
Guillaume 2020년 1월 29일
easiest way is probably with:
newarray = regexprep(yourstringarray, '-1$', '');
works with cell arrays of char vectors as well.

Ajay Kumar
Ajay Kumar 2020년 1월 29일
편집: Ajay Kumar 2020년 1월 29일
play with positions. For eg:
S = 'sectioned-1';
S = S(1:end-2)
For an array, write this in a simple for loop.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by