5

Is it possible to insert a backspace after a string.If possible then How to insert a back space in a string??

Naveen
  • 111
  • 1
  • 2
  • 8

3 Answers3

12

The escape sequence for backspace is:

\b

https://social.msdn.microsoft.com/Forums/en-US/cf2e3220-dc8d-4de7-96d3-44dd93a52423/what-character-escape-sequences-are-available-in-c?forum=csharpgeneral

C# defines the following character escape sequences:

  • \' - single quote, needed for character literals
  • \" - double quote, needed for string literals
  • \\ - backslash
  • \0 – Null
  • \a - Alert
  • \b - Backspace
  • \f - Form feed
  • \n - New line
  • \r - Carriage return
  • \t - Horizontal tab
  • \v - Vertical quote
  • \u - Unicode escape sequence for character
  • \U - Unicode escape sequence for surrogate pairs.
  • \x - Unicode escape sequence similar to "\u" except with variable length.
Maku
  • 1,464
  • 11
  • 20
5

Depends on what you are trying to achieve. To simply remove the last character you could use this:

string originalString = "This is a long string";
string removeLast = originalString.Substring(0, originalString.Length - 1);

That removeLast would give This is a long strin

Belogix
  • 8,129
  • 1
  • 27
  • 32
2

this will insert a backspace in the string

string str = "this is some text";
Console.Write(str);
Console.ReadKey();
str += "\b ";
Console.Write(str);
Console.ReadKey();
//this will make "this is some tex _,cursor placed like so.

if its like Belogix said(to remove last char),you can do like belogix did or other way like:

string str = "this is some text";
Console.WriteLine(str);
Console.ReadKey();

Console.WriteLine(str.Remove(str.Length - 1,1));
Console.ReadKey();

or just:

string str = "this is some text";
Console.WriteLine(str + "\b ");
slavoo
  • 5,798
  • 64
  • 37
  • 39
terrybozzio
  • 4,424
  • 1
  • 19
  • 25