I'm looking to split this string in 4 parts. So far i'm only able to split it using components(separatedBy:) method. However i want i also to last word teamId4 into 2 parts where i can get teamId and 4 the number. All the solutions i have looked at always have separators in them like string having either spaces, lines, full stops etc which makes it quite easy. How can i achieve this output player23, 8, teamId, 4
var player = "player23_8_chelseaId4" var splittedString: [String] { let stringArray = player.components(separatedBy: "_") let playerID = stringArray[0] let playerIndex = stringArray[1] let team = stringArray[2] // Would like "4" as the last string in the array let array = [playerID, playerIndex, team] return array } This is the output so far
["player23", "8", "chelseaId4"] Desired output would be
["player23", "8", "chelseaId", "4"]
23is always included along with the players name