问题描述:

I am trying to split a string which contains a sequence "Song Name - Artist Name". I've done similar string manipulations in PHP with relative ease as shown below

PHP:

$titledata = explode(" - ", $title);

This is what I'm trying in C#:

string[] titledata = title.Split(" - ");

And it returns the error "Cannot convert from 'string' to 'char[]'". I've tried using ToCharArray() and while it runs, it doesn't work properly. I'm not sure if it's a problem with the minus sign or the number of characters being used as the seperator.

网友答案:

The overloads that split by strings requires them to be in an array. You'd have to do this:

string[] titledata = title.Split(new[] { " - " }, StringSplitOptions.None)
相关阅读:
Top