退格分隔的平面文件
有人见过退格分隔的平面文件吗?我的要求是解析这样的文件,但我无法将退格字符放入文件中以检查是否能够检测到它。
Has any one ever seen a backspace delimited flat file? My requirement is to parse such a file but I am not able to put a backspace character into a file to check if I am able to detect it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
分割不应该比使用任何其他分隔符更困难。毕竟,这只是另一个角色。例如,在 Python 中:
大多数语言使用
\b
作为退格键的转义字符。如果您的系统没有,您还可以包含退格键本身的 ASCII 控制代码,即 \x08。Splitting shouldn't be any harder than using any other delimiter. It's just another character, after all. In Python, for instance:
Most languages use
\b
as the escape character for a backspace. If yours doesn't you can also include the ASCII control code for backspace itself, which is \x08.我从未见过,但有些编辑器允许您先按 Ctrl-V 来输入退格字符。
I have never seen one, but some editors allow you to put a backspace character in by pressing e.g. Ctrl-V first.
您可以编写一个脚本,将退格键的 ASCII 字符代码 (
\0x008
) 附加到文件中。You could write a script that appends the ASCII character code for backspace (
\0x008
) to a file.这是一个 C 程序,它将生成一个退格分隔的文件用于测试(用换行符分隔不同的行)。传入一个文件名,或者它将其写入标准输出(我选择 C 是因为你没有提到平台;大多数人都有可用的 C 编译器):
相同的字符串文字语法 应该在 Java 中工作;我会让你编写程序的其余部分:
Here is a C program that will generate you a backspace delimited file for testing (with newlines delimiting different rows). Pass in either a filename, or it will write it to stdout (I chose C because you didn't mention a platform; most people have a C compiler available):
The same string literal syntax should work in Java; I'll let you write the rest of the program:
如果使用 Windows,您可以使用 Ctrl+Backspace 在记事本中插入退格键。
If using Windows, you can insert a backspace into notepad by using Ctrl+Backspace.
我还建议使用十六进制编辑器,例如 0xED (适用于 Mac)。它对于查看和编辑包含不常见字符的文件非常有用。有了它,您只需键入“08”即可将退格字符插入文件中。
I would also recommend getting a hex editor like 0xED (for Mac). It's pretty useful for viewing and editing files containing unusual characters. With it, you can just type "08" to insert a backspace character into a file.