Split line with spaces and minus sign

I am trying to break a line containing the sequence "Song title - artist name". I did similar string manipulations in PHP with relative ease, as shown below.

PHP:

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

This is what I am trying to use in C #:

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

And it returns the error “Unable to convert from“ string ”to“ char []. ”I tried using ToCharArray (), and while it works, it doesn’t work correctly. I'm not sure if this is a problem with the minus sign or the number of characters used in as a separator.

+3
source share
1 answer

, , , . :

string[] titledata = title.Split(new[] { " - " }, StringSplitOptions.None)
+7

Source: https://habr.com/ru/post/1774657/


All Articles