Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Zeynab Mousavikhamene
Zeynab Mousavikhamene el 29 de En. de 2020
Respondida: Guillaume el 29 de En. de 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?

Respuestas (2)

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

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

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by