简体   繁体   English

删除八度中的非ASCII字符

[英]Remove non ASCII characters in octave

I'm trying to remove non ASCII characters read from a data file using OCTAVE but I can't make it work. 我正在尝试使用OCTAVE删除从数据文件中读取的非ASCII字符,但无法使其正常工作。 I tried getting the ASCII codes of these "weird" characters and they do have random ASCII codes. 我尝试获取这些“怪异”字符的ASCII码,并且它们确实具有随机的ASCII码。 An example string of characters is this: 一个示例字符串是这样的:

asdqwФЕДЕРАЛЬ234НОЕ234 АГЕНТСqewwqedasТВО ПasdsadО ОБРАasdasdЗОВАНИЮ Госудаsadasdsagwfрственная акадеasdмия профессиональной п asdqwФЕДЕРАЛЬ234НОЕ234АГЕНТСqewwqedasТВОПasdsadООБРАasdasdЗОВАНИЮГосудаsadasdsagwfрственнаяакадеasdмияпрофесси

Do you guys have any suggestions on how can i remove the non ASCII characters from this string? 你们对如何从此字符串中删除非ASCII字符有任何建议吗? Or better yet, how will I be able to determine if a given string has non ASCII characters? 或者更好的是,如何确定给定的字符串是否包含非ASCII字符?

Thanks in advance! 提前致谢!

To remove all non ASCII chars in the range of 0..127 decimal use 要删除范围为0..127十进制的所有非ASCII字符,请使用

a = "asdqwФЕДЕРАЛЬ234НОЕ234 АГЕНТСqewwqedasТВО ПasdsadО ОБРАasdasdЗОВАНИЮ Госудаsadasdsagwfрственная акадеasdмия профессиональной п";
a(! isascii (a)) = []

which gives 这使

a = asdqw234234 qewwqedas asdsad asdasd sadasdsagwf asd 

and if you just want to check if there are non ASCII chars: 以及是否只想检查是否存在非ASCII字符:

any (! isascii("foobar"))
ans = 0
any (! isascii("foobaröäüß"))
ans =  1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM