Search code examples
stringmatlabnon-ascii-characters

check for non ascii characters in matlab


i have a result string that sometimes hold non ascii values. These non ascii values cause trouble so i need to check for their presence in the result string.

i tried with these two methods

if (regexpi(result , ^\s\x{20}-\x{7e}))
display('non ascii');
end

and

if any(result  < 128)
else
display('non ascii');
end

but it didn't work. Any help is greatly appreciated.


Solution

  • small tweak to the above:

    if all(result  < 128)
    else
    display('non ascii');
    end
    

    or

    if any(result  > 127)
    display('non ascii');
    end