how I can know if a string is empty or not!?

177 views (last 30 days)
Imen Mani
Imen Mani on 15 May 2016
Edited: Stephen23 on 8 May 2020
please help me with a code ! thank you !

Accepted Answer

Guillaume
Guillaume on 15 May 2016
Edited: Guillaume on 15 May 2016
How about the helpfully named isempty?:
>>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 Comments
Stephen23
Stephen23 on 8 May 2020
"" 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:

Sign in to comment.

More Answers (1)

Weird Rando
Weird Rando on 15 May 2016
Edited: Weird Rando on 15 May 2016
You can use the length()
a = '';
stringlen = length(a) % stringlen = 0

Community Treasure Hunt

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

Start Hunting!

Translated by