Alex Rivera | Logout

C# array get last item from split in one line

Asked 2011-10-18T21:27:42.323
11

I know that this works to get the first item of an array

string aString = @"hello/all\this\is/a\test";
string firstItemOfSplit = aString.Split(new char[] {'\\', '/'})[0];
//firstItemOfSplit = hello

is there a way to get the last item? Something like

string aString = @"hello/all\this\is/a\test";
string lastItemOfSplit = aString.Split(new char[] {'\\', '/'})[index.last];
//lastItemOfSplit = test
Edit
Report

1 Answer

0

this one i tried and it worked.

  string LastItem= (@"hello/all\this\is/a\test").Split(new char[] {@"\"[0], "/"[0]}).Last();
  Console.WriteLine(LastItem);
answered 2011-10-18T21:32:38.273

Your Answer