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

251 ビュー (過去 30 日間)
Philipp Mueller
Philipp Mueller 2020 年 5 月 15 日
回答済み: the cyclist 2022 年 4 月 28 日
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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by