C# 如何在字符串末尾插入一个退格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17408296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:25:29  来源:igfitidea点击:

How to insert a back space after the end of string

c#.netstringwordbackspace

提问by Naveen

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

是否可以在字符串后插入退格。如果可能,那么如何在字符串中插入退格?

回答by Belogix

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 removeLastwould give This is a long strin

removeLast会给这是一个长字符串

回答by terrybozzio

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:

如果它像 Belogix 说的(删除最后一个字符),你可以像 belogix 那样做或其他方式:

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 ");