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

330 次查看(过去 30 天)
Hello,
How can i delete the first two characters of this string? Thank you
string='W987';

采纳的回答

KSSV
KSSV 2020-5-15
编辑:KSSV 2020-5-15
string(1:2) = [] % To remove the firt two elements

更多回答(1 个)

the cyclist
the cyclist 2022-4-28
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"

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by