C# SubString() 方法用于从字符串中获取子字符串。子字符串从指定的字符位置开始,一直持续到字符串的末尾。
public string Substring(Int32 index) public string Substring(Int32, Int32)
index:它是一个整数类型参数,用于传递索引以获取子字符串。
它返回一个字符串。
using System; public class StringExample { public static void Main(string[] args) { string s1 = "Hello C Sharp"; string s2 = s1.Substring(5); Console.WriteLine(s2); } }
输出:
C Sharp