-1

I am having trouble trying to figure this topic out. Like the topic, How do I delete an element that contains a letter in Array. This is the code I have so far.

let newline = "\n"
    let task = Process()
    task.launchPath = "/bin/sh"
    task.arguments = ["-c", "traceroute -nm 18 -q 1 8.8.8.8"]

    let pipe = Pipe()
    task.standardOutput = pipe
    task.launch()
    let data = pipe.fileHandleForReading.readDataToEndOfFile()
    let output = NSString(data: data, encoding: String.Encoding.utf8.rawValue) as! String
    var array = output.components(separatedBy: "  ")
    array = array.filter(){$0 != "m"}



    print(array, newline)

I have tried multiple options given by this stack overflow. How to remove an element from an array in Swift

I think I have hit a wall.

Community
  • 1
  • 1
JonnyTombstone
  • 219
  • 1
  • 2
  • 6

1 Answers1

1

Have you tried

array = array.filter({ !$0.contains("m") })
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
David
  • 77
  • 2
  • 10