Recognize Number/Special Characters

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
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
Walter Roberson 2011년 11월 8일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

태그

질문:

Nil
2011년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by