how I can know if a string is empty or not!?
조회 수: 66 (최근 30일)
이전 댓글 표시
채택된 답변
Guillaume
2016년 5월 15일
편집: Guillaume
2016년 5월 15일
>>isempty('aaa')
ans =
0
>>isempty('')
ans =
1
Note that because strings are just matrices (of characters), it's the same test you use for matrix emptiness.
댓글 수: 4
Adam Danz
2020년 5월 7일
편집: Adam Danz
2020년 5월 7일
For strings or char arrays, you can use,
TF = strlength(s)==0; % r2016b or later
Demo
strlength('word') % ans = 4
strlength("word") % ans = 4
strlength("") % ans = 0
strlength('') % ans = 0
If the string is scalar,
isempty(char(s))
Demo
s = "";
isempty(char(s)) % ans = 1
Stephen23
2020년 5월 8일
편집: Stephen23
2020년 5월 8일
"" is not an empty string array, it is a scalar string array (which happens to have zero characters, but the number of characters is totally irrelevant to the size of the string array):
>> isscalar("aaaaaaaaa")
ans=
1
>> isscalar("")
ans=
1
If you want to know how many characters are in the elements of a string array, use strlength:
추가 답변 (1개)
Weird Rando
2016년 5월 15일
편집: Weird Rando
2016년 5월 15일
You can use the length()
a = '';
stringlen = length(a) % stringlen = 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!