Files
freeCodeCamp/guide/english/csharp/substring/index.md

32 lines
806 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Substring
---
# Substring
`Substring` extracts a portion of a string value. It is used with 2 integer parameters, the first is location of the first character(starts with index 0) and the second is the desired character length. If only one parameter is used, it will be the location
of the first character, and the rest of the string is returned from the starting position.
2018-10-12 15:37:13 -04:00
## Example
```
string firstSentence = "Apple, I have.";
string secondSentence = "I have a Pen.";
string thirdSentence = "I am having Fun";
2018-10-12 15:37:13 -04:00
string apple = firstSentence.Substring(0,5);
string pen = secondSentence.Substring(9,3);
string fun = thirdSentence.Substring(12);
2018-10-12 15:37:13 -04:00
Console.WriteLine(apple);
Console.WriteLine(pen);
Console.WriteLine(fun)
2018-10-12 15:37:13 -04:00
```
## Output:
```
>Apple
>Pen
>Fun
2018-10-12 15:37:13 -04:00
```