2013-07-01 41 views
3

是否可以在字符串後插入退格符。如有可能,然後 如何在字符串中插入後退空間?如何在字符串末尾插入後退空間

+2

什麼是你想實現什麼? –

+0

看看Escape序列:http://msdn.microsoft.com/en-us/library/h21280bw.aspx – duDE

回答

3

取決於你想要達到的目的。簡單地刪除最後一個字符,你可以這樣做:

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

removeLast會給這是一個漫長〜應變

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