Use of Substring in Level 3 Assignment 2

Can anyone explain the components of this in bold? I don’t know .NET but I do understand splitting a string using a CRLF as a delimiter. I’ve done simple operations with substring, successfully experimenting but not with the .ToCharArray method. Also the general structure of the statement with the “0” index I do not understand.

VendorInformation.Split(Environment.NewLine.ToCharArray)(0).Substring("TaxID: ".Length)

Splitting string with new line , take first element of output and then take string after TaxID

VendorInformation.Split(Environment.NewLine. ToCharArray )( 0 ).Substring("TaxID: ".Length)ets take

this exaple

TaxID: 1234
JobID: 2345

VendorInformation.Split(Environment.NewLine. ToCharArray ) this expression will return array of strings as following
{TaxID:1234,JobID: 2345}

(0) means take first element of array ie TaxID: 1234

Subtring this 1st element after TaxID

So output will be 1234.

Ps-you need to trim the result as it contains some extra space

1 Like

Thanks. I see that this is just a continuing hierarchy. I have done a split but it seems that the “.ToCharArray” is NOT necessary. So why is it there?

My brain would have created two lines to accomplish this but I see each “.” creates a successive result to build upon
Test1 = Test.Split(Environment.NewLine)
Test1(0).Substring("Name: ".Length)

Although less readable IMHO but it accomplishes it in one line (no ToChar):
Test.Split(Environment.NewLine)(0).Substring("Name: ".Length)

Why would they put that? Is it necessary or a best practice although a default behavior?