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)
更多回答(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!