Reputation: 187
I have an array called coordinateArray that is holding this data:
["(19.452187074041884", " -99.1457748413086)", "(19.443769985032485", " -99.14852142333984)", "(19.443446242121073", " -99.13787841796875)", "(19.450244707639662", " -99.13822174072266)"]
["(19.407780723677718", " -99.18417591514299)", "(19.400373302640162", " -99.18473381461808)", "(19.400049473260434", " -99.18039936485002)", "(19.405433052977592", " -99.17838234367082)"]
["(19.4022042123319", " -99.1457748413086)", "(19.401070819438004", " -99.16139602661133)", "(19.39184146912981", " -99.16268348693848)", "(19.389736456288546", " -99.14706230163574)"]
["(19.42114689571205", " -99.17375564575195)", "(19.425598915444077", " -99.15392875671387)", "(19.414913863184566", " -99.15470123291016)", "(19.41264724664359", " -99.16594505310059)", "(19.412890099927345", " -99.16766166687012)"]
I need to remove the parenthesis from each coordinate
How can I do this in Swift 3.0?
I tried to do this
let coordinateArray = coor.components(separatedBy: ",")
var coordinateArrayF = [String]()
for coordinate in coordinateArray {
let coordinatevar = coordinate.replacingOccurrences(of: "()", with: "")
coordinateArrayF.append(coordinatevar)
}
But it isn't working what am I doing wrong?
Upvotes: 0
Views: 33
Reputation: 587
Functional programming is your friend!
var data = ["(19.452187074041884", " -99.1457748413086)", "(19.443769985032485", " -99.14852142333984)", "(19.443446242121073", " -99.13787841796875)", "(19.450244707639662", " -99.13822174072266)"]
let cleanData = data.map {
item in item.replacingOccurrences(of: "(", with: "")
}
Upvotes: 1