Why is isstr not recommended?
15 次查看(过去 30 天)
显示 更早的评论
When using isstr in my code, I get a warning that it is not recommended and I should use ischar instead. But ischar doesn't provide the same functionality as isstr. For a string, ischar returns 0 and isstr returns 1, while for a character array, ischar returns 1 and isstr returns 1. There doesn't seem to be any replacement for isstr that provides the same functionality. Why is this warning displayed?
0 个评论
采纳的回答
Star Strider
2019-1-25
2 个评论
Star Strider
2019-1-28
I don’t believe MathWorks is actually ‘recommending’ one over the other, just doing its best to avoid ambiguity. It very much depends on what you’re testing.
Example —
s = "string!";
c = 'character!';
ischar_test = [ischar(s) ischar(c)]
isstring_test = [isstring(s) isstring(c)]
isstr_test = [isstr(s) isstr(c)]
produces:
ischar_test =
1×2 logical array
0 1
isstring_test =
1×2 logical array
1 0
isstr_test =
1×2 logical array
0 1
This also illustrates the problem with isstr.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!