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

520 B
Raw Blame History

title localeTitle
Substring

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