如何输出带有特殊字符的数据? [英] How can I output data with special characters visible?

查看:137
本文介绍了如何输出带有特殊字符的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提供给我的文本文件,没有人知道它上面的编码。在文本编辑器中查看它,一切看起来都很好,正确对齐整齐的列。

I have a text file that was provided to me and no one knows the encoding on it. Looking at it in a text editor, everything looks fine, aligned properly into neat columns.

然而,当我读取数据时,我发现了一些异常现象。即使在视觉上,字段Foo出现在文本文件的相同列中(例如,在第15-20列中),当我尝试使用 substring(15,20)将其拉出时我的数据变化很大。有时候我会把字节11-16,有时是18-23,有时是15-20 ......记录之间没有一致性。

However, I'm seeing some anomalies when I read the data. Even though, visually, the field "Foo" appears in the same columns in the text file (for instance, in columns 15-20), when I try to pull it out using substring(15,20) my data varies wildly. Sometimes I'll pull bytes 11-16, sometimes 18-23, sometimes 15-20...there's no consistency between records.

我怀疑有一些特殊的图表,对我的文本编辑器是不可见的,但是可以读取(并且在索引中计算) String 方法。在Java中是否有任何方法可以使用任何可见的特殊字符转储文件的内容,这样我就可以看到我需要使用正则表达式替换字符串?

I suspect that there are some special chartacters, invisible to my text editor, but readable by (and counted in the index of) the String methods. Is there any way in Java to dump the contents of the file with any special characters visible so I can see what I need to Strings I need replace with regex?

如果没有在Java中,任何人都可以推荐一种可以帮助我的工具吗?

If not in Java, can anyone recommed a tool that may be able to help me out?

推荐答案

我首先要直接查看该文件。任何代码都会增加一层疑问。拿一个Total Commander(或平台上的等效命令),查看文件(F3)并切换到十六进制模式。您建议行之间的特殊字符行为甚至不一致,因此在尝试通过算法修复之前,您应该获得有关格式的一些视觉线索。

I would start with having a look at the file directly. Any code adds a layer of doubt. Take a Total Commander (or equivalent on your platform), view the file (F3) and switch to hex mode. You suggest that the special characters behavior is not even consistent between lines, so you should get some visual clue about the format before you even attempt to fix it algorithmically.

这篇关于如何输出带有特殊字符的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆