Recognize Number/Special Characters
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I have below input string and from it I want to recognize digits/special characters, May be some flag can be set
txt='har23#$'
Like if alphabet then flag=1 and for digits/Special Characters flag=0
Pls provide me some direction..
Thanks in Advance..
1 个评论
Sven
2011-11-8
Have you used regular expressions before? They can be quite useful.
txt='har23#$';
badChars = regexp(txt,'[^A-Za-z0-9]');
if isempty(badChars)
disp 'All valid characters'
else
fprintf('Bad characters detected: %s\n', txt(badChars))
end
采纳的回答
Walter Roberson
2011-11-8
txtisalpha = ismember(txt, ['a':'z', 'A':'Z']);
Then txtisalpha will be a vector with true for English letters and false for other characters (including spaces).
0 个评论
更多回答(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!