left characters of a string
조회 수: 46 (최근 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에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!