MATLAB Answers

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

1 view (last 30 days)
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 29 Jan 2020
Answered: Guillaume on 29 Jan 2020
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?

  0 Comments

Sign in to comment.

Answers (2)

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

  0 Comments

Sign in to comment.


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

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags