So I’m messing around with some Fantasy Football data for a little coding project. I have a spread sheet that has the following information from a daily fantasy football contest I played in.
A full lineup of players (1 QB, 2 RB, 3 WR, 1 TE, 1 FLEX (can be a RB WR or TE) and a Defense)
Where that lineup finished in the contest.
The total number of points scored by that lineup.
I have a few ideas for some data analysis I would like to do, but I need to break up the lineups a little differently. Currently each String element in the “Lineups” tab in the spread sheet looks like this:
String = "QB Dak Prescott RB Darrell Henderson Jr. RB Darrel Williams FLEX J.D. McKissic WR Cooper Kupp WR CeeDee Lamb WR Adam Thielen TE Ricky Seals-Jones DST Colts"
The general format is “Position FirstName LastName…repeat”
My idea was to use something like indexOf() to find the instances of each of the positions in the String, then use those results to get a substring with each player and their corresponding positions.
I know indexOf() only works for the first instance of a position. So if I did:
on the existing string it would only give me the first instance of those letters occurring. My thought is I could run a loop where indexOf() finds a position index, I take out that one position I need, then on the remaining string rerun indexOf() in order to break each element I need out of the first string.
My question, is there an existing function that does this and I’m just making a bunch of work for myself for no reason? Or, is there potentially a better logical way to go about this problem that I’m not using?
Thank you all as always for the help.