1

I need to split a string describing a soccer match into home team and away team.

The string will always be something like "Manchester United v Liverpool".

I need to split on ' v ' - i know that - I just don't know how to do it in C#

I tried

 string s = item.Summary;
 string[] teams = s.Split('v');
 tempEvent.HomeTeam = teams[0].Trim();
 tempEvent.AwayTeam = teams[1].Trim();

but naturally that made the above mentioned game be between Manchester United and Li

0

1 Answer 1

5

Try this code:

string game = "Manchester United v Liverpool";
string[] teams = game.Split(new[] { " v " }, StringSplitOptions.None);

It will split the string on [interval]v[interval].

So if game is Manchester United v Liverpool the two strings in teams will be Manchester United and Liverpool.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Oh, I tried that first resulting in "Argument type 'string' is not assignable to paramater type 'char
If so you can select this answer as best :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.