String.Substring 方法 (Int32, Int32)
来源:互联网 发布:数据集中存储的好处 编辑:程序博客网 时间:2024/05/21 00:15
String.Substring 方法 (Int32, Int32)
从此实例检索子字符串。 子字符串从指定的字符位置开始且具有指定的长度。
程序集: mscorlib(在 mscorlib.dll 中)
语法
public string Substring(int startIndex,int length)
参数
- startIndex
- 类型:System.Int32
此实例中子字符串的起始字符位置(从零开始)。
- length
- 类型:System.Int32
子字符串中的字符数。
返回值
类型:System.String与此实例中在 startIndex 处开头、长度为 length 的子字符串等效的一个字符串,如果 startIndex 等于此实例的长度且 length 为零,则为 Empty。
异常
startIndex 加 length 之和指示的位置不在此实例中。
- 或 -
startIndex 或 length 小于零。
备注
startIndex is zero-based.
This method does not modify the value of the current instance. Instead, it returns a new string with length characters starting from the startIndexposition in the current string.
示例
The following example uses the Substring method in three cases to isolate substrings within a string. In two cases the substrings are used in comparisons, and in the third case an exception is thrown because invalid parameters are specified.
String myString = "abc";bool test1 = myString.Substring(2, 1).Equals("c"); // This is true.Console.WriteLine(test1);bool test2 = String.IsNullOrEmpty(myString.Substring(3, 0)); // This is true.Console.WriteLine(test2);try { string str3 = myString.Substring(3, 1); // This throws ArgumentOutOfRangeException. Console.WriteLine(str3);}catch (ArgumentOutOfRangeException e) { Console.WriteLine(e.Message);}
版本信息
.NET Framework
受以下版本支持:4.5、4、3.5、3.0、2.0、1.1、1.0.NET Framework Client Profile
受以下版本支持:4、3.5 SP1可移植类库
受以下版本支持:可移植类库适用于 Windows 应用商店应用的 .NET
受以下版本支持:Windows 8平台
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(不支持服务器核心角色), Windows Server 2008 R2(支持带 SP1 或更高版本的服务器核心角色;不支持 Itanium)
并不是.NET Framework 对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求.请参阅
参考
社区附加资源
添加- String.Substring 方法 (Int32, Int32)
- Int32.TryParse (String, Int32)
- GraphicsPath.AddArc 方法 (Int32, Int32, Int32, Int32, Single, Single)
- VB String.Split 方法 (String[], Int32, StringSplitOptions)
- Int32.Parse(string)
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String) 或 “Int32 Parse(System.String)”
- Stream::Read 方法 (array<Byte>^, Int32, Int32)
- Stream::Read 方法 (array<Byte>^, Int32, Int32)
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String)
- Point.Offset 方法 (Int32, Int32) &&Point.Offset 方法 (Point)
- EF 错误LINQ to Entities 不识别方法“Int32 ToInt32(System.String)
- String和string的区别,int Int32依次类推
- C#中String与string,Int32与int
- C#:Convert.ToInt32(String)和Int32.Parse(String)的区别
- LINQ to Entities 不识别方法“Int32 ToInt32(System.String)”,因此该方法无法转换为存储表达式
- 关于用DataTable.Select()方法出现“无法在 System.String 和 System.Int32 上执行“=”操作。”错误的原因
- TreeView插入节点的方法:TreeNodeCollection.Insert 方法 (Int32, TreeNode)
- 使用Int32.parse()方法要保证输入参数的正确性
- 黑马程序员_学习笔记9——字符串
- UNIX环境高级编程(三)文件IO
- STM32中assert_param的使用
- windows核心编程(一) -----windows消息分流器
- 梳理springmvc
- String.Substring 方法 (Int32, Int32)
- 程序员加班到深夜,你经历过没?
- VMware虚拟机下Linux平台搭建samba服务器的基本配置
- 黑马程序员——类的本质
- 编译器级别的代码优化对比
- LeetCode-Wildcard Matching
- Zookeeper中节点属性中的 三个 Zxid
- 学生宿舍管理系统类图设计
- View---visibility属性VISIBLE、INVISIBLE、GONE的区别