How to delete the first or the first two characters in a string?

304 vues (au cours des 30 derniers jours)
Philipp Mueller
Philipp Mueller le 15 Mai 2020
Hello,
How can i delete the first two characters of this string? Thank you
string='W987';

Réponse acceptée

KSSV
KSSV le 15 Mai 2020
Modifié(e) : KSSV le 15 Mai 2020
string(1:2) = [] % To remove the firt two elements

Plus de réponses (1)

the cyclist
the cyclist le 28 Avr 2022
In modern MATLAB parlance, 'W987' is a character array, not a string.
@KSSV's answer is accurate in your case, but will not work on the string "W987". The following will work for either a character array or a string:
c = 'W987';
eraseBetween(c,1,2)
ans = '87'
s = "W987";
eraseBetween(s,1,2)
ans = "87"

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by