I have a question.
There are several ways to divide a string into a string array.
First of all, the way I made a string into a string array is,
let str = "F'2R'UU2"
let strArr: [String] = str.map { String($0) }
//strArr => ["F", "'", "2", "R", "'", "U", "U", "2"]
It turns into a string array like this
But I would like to divide based on the uppercase alphabet. For example, if you divide the string F2
, it becomes ["F2"]
instead of ["F", "2"]
, and if you divide the string F'2
, it becomes ["F", "'", "2"]
instead of ["F'2"]
The result I want is,
let str = "F'2R'UU2"
<<<str to strArr>>>
//strArr => ["F'2", "R'", "U", "U2"]
Please let me know!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…