-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.

1 Answer 1

1

Have you tried

array = array.filter({ !$0.contains("m") })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.