如何在字符串结尾后插入后退空格

时间:2013-07-01 15:34:18

标签: c# .net string word backspace

是否可以在字符串后插入退格。如果可能的话 如何在字符串中插入后退空间??

3 个答案:

答案 0 :(得分:9)

答案 1 :(得分:3)

取决于您想要实现的目标。要简单地删除最后一个字符,您可以使用它:

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

removeLast会给出这是一个很长的路径

答案 2 :(得分:1)

这将在字符串

中插入退格
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.

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

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

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

或只是:

string str = "this is some text";
Console.WriteLine(str + "\b ");