在C#中,substring方法用于从一个字符串中提取子字符串。其高级用法包括以下几种:
string str = "Hello World"; string sub = str.Substring(6, 5); // 输出 "World" string str = "Hello World"; string sub = str.Substring(6); // 输出 "World" string str = "Hello World"; int startIndex = str.IndexOf("World"); string sub = str.Substring(startIndex); // 输出 "World" string str = "Hello World Hello"; int startIndex = str.LastIndexOf("Hello"); string sub = str.Substring(startIndex); // 输出 "Hello" 总的来说,Substring方法在C#中提供了灵活的子字符串提取功能,可以根据具体需求选择合适的用法进行操作。