问题描述
我想最后三个字符从字符串中删除:
字符串的myString =abcdxxx;
请注意该字符串是动态的数据。
I want to remove last three characters from a string:
string myString = "abcdxxx";
Note that the string is dynamic data.
You can use string.Substring and give it the starting index and it will get the substring starting from given index till end.
myString.Substring(str.Length-3)
Edit, for updated post
To remove last three characters from string you can use string.Substring(Int32, Int32) and give it the starting index 0
and end index three less then the string length. It will get the substring before last three characters.
myString = myString.Substring(0, str.Length-3);
String.Substring Method (Int32, Int32)
You can also using String.Remove(Int32) method to remove the last three characters by passing start index as length - 3, it will remove from this point to end of string.
myString = myString.Remove(myString.Length-3)
这篇关于从字符串中删除最后三个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!