Question: Inside a For loop I do not understand following behavior of `string.Substring(i,j)`

having the code

```
String line = "TTACCTTAAC";
int k = 3; //this is variable but for simplicity is 3
String _pattern = "";
for (int i = 0; i <= line.Length - k; i++) {
    _pattern = line.Substring(i, i + k );
    //do something...
}

```

I am expecting the loop to walk over string Line (`TACCTTAAC`) `(from 0 to 10-3 = 7)`like:

```
TTA
ACC
CCT
CTT
TTA
TAA
AAC

```

However I get

```
TTA
ACCT
etc...

```

What am I missing?

Answer: 
Second parameter of `Substring` is `length`, not `end`, so you should just pass `k` instead of doing your math:

```
String line = "TTACCTTAAC";
int k = 3; //this is variable but for simplicity is 3
String _pattern = "";
for (int i = 0; i <= line.Length - k; i++) {
    _pattern = line.Substring(i, k);
    //do something...
}

```
substring function in c# is used as string.Substring(int startindex, int Length)

so you should use 

```
_pattern = line.Substring(i, k);

```