How to check the numbers of characters of a string?
9 次查看(过去 30 天)
显示 更早的评论
e.g I have a string, abcde. And I need a checker to check whether the string has 5 characters before executing a command.
0 个评论
采纳的回答
Pedro Villena
2012-10-31
编辑:Pedro Villena
2012-10-31
str = num2str([17;10],'%05i')
if length(str(1,:))==5,
%%%here is your command
end
or
str = num2str([17;10],'%05i')
if numel(str(1,:))==5,
%%%here is your command
end
3 个评论
Matt Fig
2012-10-31
Better to use NUMEL, for generality.
S = ['ertyu';'poiuy';'lkjhg';'nbvcx']
length(S)
numel(S)
更多回答(4 个)
另请参阅
类别
在 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!