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.
I have never seen one, but some editors allow you to put a backspace character in by pressing e.g. Ctrl-V first.
You could write a script that appends the ASCII character code for backspace (\0x008
) to a file.
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.
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"
If using Windows, you can insert a backspace into notepad by using Ctrl+Backspace.