简体   繁体   English

Android无法识别的字符显示为“?”

[英]Android unrecognized characters are displayed as “?”

I have an app than parses a csv and diplays its content. 我有一个应用程序,而不是解析csv和diplays其内容。 My problem is it displays '-' as '?' 我的问题是它显示' - '为'?' inside a diamond. 钻石里面。 What can I do so that it wouldn't display as such? 我该怎么做才能显示出来?

EDIT: here's my code for opening the file 编辑:这是我打开文件的代码

InputStream input = openFileInput("pms.csv");
SchedController.reader = new CSVReader(new InputStreamReader(input, "US-ASCII"));
SchedController.sched = SchedController.reader.readAll();
input.close();

I have tried US-ASCII , UTF-8 ... 我试过US-ASCIIUTF-8 ......

The suggested encodings on the previous answers did not solve my case. 对先前答案的建议编码并没有解决我的问题。 I tried the encoding "windows-1252" which I found out here and it worked: 我尝试了编码“windows-1252”,我在这里发现它有效:

CSVReader reader = new CSVReader(new InputStreamReader(input, "windows-1252"));

You can set Encoding type by: 您可以通过以下方式设置编码类型:

StandardFonts.WIN_ANSI_ENCODING

or can make changes in the string as: 或者可以在字符串中进行更改:

       newString = oldString.replace(")", "\\)");
       newString = oldString.replace("(", "\\(");

尝试将字符编码更改为UTF-8

SchedController.reader = new CSVReader(new InputStreamReader(input, "UTF-8"));

You can also refer to below post 你也可以参考下面的帖子

https://stackoverflow.com/a/2680834/1441666 https://stackoverflow.com/a/2680834/1441666

Android support the following encodings Android支持以下编码

  • Xml.Encoding ISO_8859_1 Xml.Encoding ISO_8859_1
  • Xml.Encoding US_ASCII Xml.Encoding US_ASCII
  • Xml.Encoding UTF_16 Xml.Encoding UTF_16
  • Xml.Encoding UTF_8 Xml.Encoding UTF_8

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

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