C#substrings:删除前三个字符

Phi*_*hil 2 c# string substring

我有一个字符串,我想删除前三个字符.我如何使用子串进行此操作,还是有其他方法?

string temp = "01_Barnsley"
string textIWant = "Barnsley"
Run Code Online (Sandbox Code Playgroud)

谢谢

Son*_*nül 18

你可以使用String.Substring(Int32)方法.

从此实例中检索子字符串.子字符串从指定的字符位置开始,并继续到字符串的末尾.

string textIWant = temp.Substring(3);
Run Code Online (Sandbox Code Playgroud)

这是一个demonstration.

作为替代方案,您也可以使用String.Remove method(Int32, Int32)方法.

返回一个新字符串,其中删除了从指定位置开始的当前实例中指定数量的字符.

string textIWant = temp.Remove(0, 3);
Run Code Online (Sandbox Code Playgroud)

这是一个demonstration.

  • +1,即使仅用于按钮效果. (2认同)