left characters of a string
110 ビュー (過去 30 日間)
古いコメントを表示
if I have a name 'Microsoft', how can i get the first 6 characters 'Micros'?
0 件のコメント
採用された回答
Andrei Bobrov
2011 年 7 月 6 日
name = 'Microsoft'
out = name(1:6)
2 件のコメント
Stephen23
2022 年 11 月 26 日
name = 'Microsoft';
name(1:min(end,6))
name = 'Cat';
name(1:min(end,6))
その他の回答 (1 件)
Steven Lord
2022 年 11 月 26 日
This wasn't an option when the question was originally asked, but the extractBefore function will work for both char vectors and string arrays.
c = 'Microsoft'
c6 = extractBefore(c, 7)
s = string(c)
s6 = extractBefore(s, 7)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で String についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!