Capture Outputs

Why doesn’t this work?

using System;

namespace CaptureOutput
{
class Program
{
static void Main(string args)
{
string designer = “Anders Hejlsberg”;
int indexOfSpace = designer.IndexOf(" ");
string secondName = designer.Substring(indexOfSpace, designer.Length-1);
Console.WriteLine(secondName);
}
}
}

1 Like

Take a look at the documentation -> https://docs.microsoft.com/en-us/dotnet/api/system.string.substring?view=netframework-4.8#System_String_Substring_System_Int32_System_Int32_

The second parameter of the Substring method is the number of the characters in the substring, not the end index.

3 Likes