本文介绍了从字符串中删除最后三个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想最后三个字符从字符串中删除:

 字符串的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)

String.Remove Method (Int32)

这篇关于从字符串中删除最后三个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:08