Translate Swift to xojo

Hello,
Does anyone know how to translate these few lines of Swift into xojo language?

let data = runCMD(app: "/usr/sbin/netstat", args: ["-rnt"]) //shell.execute("/usr/sbin/netstat -rnt")
for line in data.split(separator: "\n") {
            if line.split(separator: " ").count > 3 {
                let linedata = String(line)
                let regex = try! NSRegularExpression(pattern: " +", options: NSRegularExpression.Options.caseInsensitive)
                let range = NSRange(location: 0, length: linedata.count)
                let normalized = regex.stringByReplacingMatches(in: linedata, options: [], range: range, withTemplate: "\t")
                let info = normalized.split(separator: "\t")
                if info[0] == "default", info[1].contains("link#") {
                    return true
            }
        }
        return false
    }

Thanks

That’s just a shell with some splits and regex.

  1. Do a shell
  2. Split the result by newlines
  3. Nthfield with " " and count > 3
  4. Regex " + "
  5. Haven’t a clue what stringByReplacingMatches is.
1 Like

I think that replaces each run of spaces with tabs.

2 Likes

Thanks for the analysis:

  1. Do a shell : Ok (shell.execute(“/usr/sbin/netstat -rnt”)
  2. Split the result by newlines : Ok
  3. Nthfield with " " and count > 3 //if more than 3 spaces?
  4. Regex " + " //I don’t know anything about Regex!

Thanks.
let info = normalized.split(separator: “\t”) >> normalized.Split(Chr(9)) ?

According to ChatGPT, the “regex.stringByReplacingMatches” method is used to perform the replacement in the “linedata” string. The “withTemplate” option specifies the replacement string, in this case, “\t”.

somehow the replace from space to tab is unnecessary.
the whole block with regex is unnecessary.
is just look each row if the first column is “default” and the second column contains a “link#”

Thank you for your remarks. It is very interesting. I will do some tests.