What is the purpose of Unicode "Backspace" U+0008?
Asked Answered
R

1

15

What is the purpose of the Unicode Character 'BACKSPACE' (U+0008) in programming? What applications can it be used for?

Repurchase answered 16/12, 2011 at 21:5 Comment(2)
If you cannot determine the purpose for a particular Unicode symbol, it probably goes into the "personal entertainment" category, just like U+2603 and U+1F4A9. :-)Weaponless
There's actually a real purpose for both of those characters: full compatibility with other character sets (both of Japanese origin, in this case!) which include those characters.Feisty
A
15

On output to a terminal, it typically moves the cursor one position to the left (depending on settings). On input, it typically erases the last entered character (depending on the application and terminal settings), though the DEL / DELETE character is also used for this purpose. Typically it can be entered by pressing Backspace or Control-H

Note that its action of deleting characters occurs only on a display, not in memory. A string within a running program can contain just about any sequence of characters (depending perhaps on the language), including backspace. In that context, it's generally just another character. For example, in C strlen("abcd\b") is 5, not 3.

In C and a number of other languages, it's represented in program source as '\b'. It's sometimes displayed as ^H.

All this applies whether it's represented as Unicode or not. The backspace character is common to most or all character sets: ASCII, Latin-1, the various Unicode representations -- even EBCDIC has a backspace character (but with a different code).

Ayeaye answered 16/12, 2011 at 21:27 Comment(19)
So adding \b to a string is more efficient than calling string=substring() or something? Will "this\b" string have a length of 3 or 5?Repurchase
"this\b" has a length of 5. Adding a backspace character to a string doesn't remove characters from the string. Its action of deleting characters occurs on the display, not in memory.Ayeaye
Note that when \b is written to a printer instead of a screen, it does overstriking instead of deletion. This allowed a primitive way to implement underlining (A\b_), boldface (A\bA), or accented characters (n\b~).Kropotkin
@dan04: Probably, but I don't know whether support for \b on printers is universal.Ayeaye
Printers that have an ascii mode should support it, since it's part of ASCII. But programs that underline with backspace (such as man) usually produced _\bA, not A\b_. That way, on terminals without overstrike, the letter overwrites the underscore and not the other way around.Syriac
@KeithThompson, This doesn't explain why the backspace character was invented in the first place.....Watters
@Pacerier: No, because that wasn't the question.Ayeaye
@KeithThompson, So what's the purpose of the backspace char?Watters
@Pacerier: I tried to explain that in my answer. What was unclear?Ayeaye
@KeithThompson, You said that it typically erase the last entered character. Why not just remove the last character then, instead of adding a backspace char?Watters
@Pacerier: What I said was that input of a backspace character typically causes the previous character to be erased (you can see this in line-oriented input and in some text editors). In that context the backspace key is a command that causes the program to erase the previous character, and the backspace character itself is not added to anything, just processed and discarded.Ayeaye
@KeithThompson, So it can be said that the backspace character exists as a hack to accomodate systems that are incapable of handling input beyond characters.Watters
@Pacerier: Yes, it can be said. You just did. I didn't. Feel free to post your own answer.Ayeaye
@KeithThompson, Ok let me try again: Would you consider the backspace character exists as a hack to accomodate systems that are incapable of handling input beyond characters?Watters
@Pacerier: Not really, no. It's part of the character I/O system, with semantics that can vary a bit from one system to another. Your statement seems to imply that you have some alternative in mind, but you haven't said what it might be.Ayeaye
@KeithThompson, An alternative would be to have two channels instead. One for input, and one for non-input (e.g. backspace).Watters
@Pacerier: And how would that be handled using a keyboard? Do you have something in mind that would be more convenient for the end user, or do I have to use a separate device to erase the last character I typed?Ayeaye
@KeithThompson, It will be only one device. Yes, the keyboard will handle two channels, except it can't, presumly because of the existance of this hack. Otherwise keyboards now will be able to handle two channels.Watters
@Pacerier: I fail to see either how this is better than the current situation, how it's relevant to the question, or how it's relevant to my answer. If you have something to say about the purpose of the backspace character, post your own answer. If you have something to say that's neither a question nor an answer, you should probably find some other place to discuss it.Ayeaye

© 2022 - 2024 — McMap. All rights reserved.