I need to split up some strings, but the number of characters and position will change, This is quite easy in PHP but seems more complicated in C#.
These are greyhound results in the UK.
I have these strings in an array, I need to extract almost everything from each string, So I need a quick and simple solution to this. I need to be able to extract the Date, Time, Course(Crayfd), Distance(540m), also the Winner only(no “Winner(s): “, need to remove this), and also the marketID from the URL.
So what built in c# functions would be best suited for all this?, a small example of some c# functions and how I use them would be great.
Also a small explanation would also be great.
[0, 0] = "BAGS cards / Crayfd 2nd Jul - 12:58 S6 540m settled"
[0, 1] = "Winner(s): Springtown Mary"
[0, 2] = "http://rss.betfair.com/Index.aspx?format=html&sportID=4339&marketID=103165302"
[1, 0] = "BAGS cards / Crayfd 2nd Jul - 12:58 TO BE PLACED settled"
[1, 1] = "Winner(s): Black Hawk Boy, Springtown Mary"
[1, 2] = "http://rss.betfair.com/Index.aspx?format=html&sportID=4339&marketID=103165303"
[2, 0] = "Forecast Betting / Crayfd (FC) 2nd July - 12:58 Forecast settled"
[2, 1] = "Winner(s): 1 - 3"
[2, 2] = "http://rss.betfair.com/Index.aspx?format=html&sportID=4339&marketID=103164570"
[3, 0] = "BAGS cards / Romfd 2nd Jul - 12:49 A2 400m settled"
[3, 1] = "Winner(s): Come On Rosie"
[3, 2] = "http://rss.betfair.com/Index.aspx?format=html&sportID=4339&marketID=103165272"
I’d suggest using String.Split, String.[Last]IndexOf, String.Substring, and LINQ extensions (simple ones, e.g.
.Last(), just to simplify things).e.g. if the URL is in
string urland it’s safe to assume the marketId is always at the end like that:Or to get things from the first line, if it’s called
courseEtc:And to look for something like a distance, you could use regex. Something like
[0-9]+m.