【问题标题】:check for non ascii characters in matlab在matlab中检查非ASCII字符
【发布时间】:2012-04-24 18:13:20
【问题描述】:

我有一个有时包含非 ascii 值的结果字符串。这些非 ascii 值会造成麻烦,因此我需要检查它们是否存在于结果字符串中。

这两种方法我都试过了

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

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

但它没有用。任何帮助是极大的赞赏。

【问题讨论】:

    标签: string matlab non-ascii-characters


    【解决方案1】:

    regexprep 可用于查找和删除非 ascii 字符。例如:

    out = regexprep(result, '[^0-9a-zA-Z.\s]+', '')
    

    Remove non ASCII characters in octave@amro 中查看 cmets

    【讨论】:

      【解决方案2】:

      对上面的小调整:

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

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

      【讨论】:

        猜你喜欢
        • 2012-12-31
        • 2013-11-19
        • 2016-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-01
        • 1970-01-01
        相关资源
        最近更新 更多