Recognize Number/Special Characters

8 visualizaciones (últimos 30 días)
Nil
Nil el 8 de Nov. de 2011
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 comentario
Sven
Sven el 8 de Nov. de 2011
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

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Nov. de 2011
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).

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by