简体   繁体   English

C# 在字符串中搜索扩展 ascii 字符

[英]C# searching for extended ascii characters in string

I have a file that I am searching for specific ascii characters.我有一个文件,我正在搜索特定的 ascii 字符。

I ran the following code after getting the text from a file:从文件中获取文本后,我运行了以下代码:

var t = text.IndexOf((char)128);

Hexedit shows I have characters of HEX 80 which is ascii character 128, but t ends up with a value of -1. Hexedit 显示我有 HEX 80 字符,即 ascii 字符 128,但 t 最终值为 -1。

Is there another way I should be searching for this character?我还有其他方法可以搜索这个角色吗?

I found I had to make a change to my encoding appropriately like the following in order be able to search the string as I expect to.我发现我必须像下面这样适当地更改我的编码,以便能够按照我的预期搜索字符串。 In my case it was the following:在我的情况下,它是以下内容:

var text = File.ReadAllText(filename, Encoding.UTF7);

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

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