2017-01-26 1 views
-1

J'ai du mal à essayer de comprendre ce sujet. Comme le sujet, comment supprimer un élément qui contient une lettre dans Array. C'est le code que j'ai jusqu'ici.comment supprimer un élément qui contient une lettre dans le tableau en utilisant swift

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) 

J'ai essayé plusieurs options données par ce débordement de pile. How to remove an element from an array in Swift

Je pense avoir touché un mur.

Répondre

1

Avez-vous essayé

array = array.filter({ !$0.contains("m") })