freeCodeCamp/guide/chinese/csharp/substring/index.md

25 lines
520 B
Markdown
Raw Normal View History

---
title: Substring
localeTitle: 子
--- # 子
`Substring`提取字符串值的一部分。它与2个整数参数一起使用第一个是第一个字符的位置以索引0开头第二个是所需的字符长度。
## 例
```
string firstSentence = "Apple, I have.";
string secondSentence = "I have a Pen.";
string apple = firstSentence.Substring(0,5);
string pen = secondSentence.Substring(9,3);
Console.WriteLine(apple);
Console.WriteLine(pen);
```
## 输出:
```
>Apple
>Pen
```