how can I remove 4 character of a string?
10 次查看(过去 30 天)
显示 更早的评论
for example string is LASTNAME ,output=NAME
0 个评论
回答(2 个)
KALYAN ACHARJYA
2018-11-20
编辑:KALYAN ACHARJYA
2018-11-20
s='lastname';
modified_s=s(5:end);
%Command Window
>> s='lastname'
>> modified_s=s(5:end)
s=lastname
modified_s=name
1 个评论
Jan
2018-11-20
s(5:end) can be interpreted as: Keep the last part. This is the same as removing the leading 4 characters:
s = 'lastname';
s(1:4) = [];
John Cunningham
2021-8-26
If s needs to be a string, just convert to character, grab the indices you need, then convert back to string.
K>> s = "lastname";
K>> s = char(s);
K>> s = string(s(5:end))
s =
"name"
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!