Does anyone know how to detect non ASCII characters in matlab.
i thought of detecting the presence of non ASCII characters through regular expressions
if (regexpi('hello world%^&%','![A-Z]*'))display('You have non ascii characters')
but it doesn’t seem to work
update:-
if (regexpi('hello word','^[A-Za-z0-9]*'))
display('You have chosen to overwrite!');
end
displays You have chosen to overwrite!
The characters
%^&are ASCII characters, they just aren’t letters. If you are wanting to test if there are any non-letters, you could do this:Note that I included a space in the search expression so that spaces are allowed in the string. To allow any whitespace character, use
'[^\sA-Z]'as the search expression.If you instead want to check for the presence of extended ASCII characters, you don’t even need regular expressions. You can just check if any of the numeric encodings for the characters in your string are greater than or equal to 128, like so: