退格分隔的平面文件

发布于 2024-08-16 14:46:02 字数 61 浏览 6 评论 0原文

有人见过退格分隔的平面文件吗?我的要求是解析这样的文件,但我无法将退格字符放入文件中以检查是否能够检测到它。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

反差帅 2024-08-23 14:46:02

分割不应该比使用任何其他分隔符更困难。毕竟,这只是另一个角色。例如,在 Python 中:

>>> x = "apples\bbanana\bcoconut\bthese are delicious!"
>>> x.split('\b')
['apples', 'banana', 'coconut', 'these are delicious!']

大多数语言使用 \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:

>>> x = "apples\bbanana\bcoconut\bthese are delicious!"
>>> x.split('\b')
['apples', 'banana', 'coconut', 'these are delicious!']

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.

猫七 2024-08-23 14:46:02

我从未见过,但有些编辑器允许您先按 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.

暮凉 2024-08-23 14:46:02

您可以编写一个脚本,将退格键的 ASCII 字符代码 (\0x008) 附加到文件中。

You could write a script that appends the ASCII character code for backspace (\0x008) to a file.

森林迷了鹿 2024-08-23 14:46:02

这是一个 C 程序,它将生成一个退格分隔的文件用于测试(用换行符分隔不同的行)。传入一个文件名,或者它将其写入标准输出(我选择 C ​​是因为你没有提到平台;大多数人都有可用的 C 编译器):

#include <stdio.h>

int main(int argc, char **argv) {
  FILE *outfile;
  if (argc < 2)
    outfile = stdout;
  else
    outfile = fopen(argv[1], "w");

  fprintf(outfile, "this\bis\nbackspace\bdelimited\n");
  fclose(outfile);

  return 0;
}

相同的字符串文字语法 应该在 Java 中工作;我会让你编写程序的其余部分:

"this\bis\nbackspace\bdelimited\n"

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):

#include <stdio.h>

int main(int argc, char **argv) {
  FILE *outfile;
  if (argc < 2)
    outfile = stdout;
  else
    outfile = fopen(argv[1], "w");

  fprintf(outfile, "this\bis\nbackspace\bdelimited\n");
  fclose(outfile);

  return 0;
}

The same string literal syntax should work in Java; I'll let you write the rest of the program:

"this\bis\nbackspace\bdelimited\n"
满意归宿 2024-08-23 14:46:02

如果使用 Windows,您可以使用 Ctrl+Backspace 在记事本中插入退格键。

If using Windows, you can insert a backspace into notepad by using Ctrl+Backspace.

情魔剑神 2024-08-23 14:46:02

我还建议使用十六进制编辑器,例如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文