Hi. I'm still a newbie, though I'm learning more every day. I'm working on an app for MacOS, and I have a couple questions regarding parsing working with big, complicated strings of text.
I have three processes that are going to be running from command-line apps that will be located in my apps main resource bundle.
The first will simply analyse the input file and return to pieces of data I need to build arguments that will be passed into the processes for the other two command-line apps.
I have a wall 'o text that is stderr and stdout piped from that process and displayed in a textfield,
I suppose my first question is...do I need to display this in the textfield to work with it?
Ideally, all the user needs to see displayed in that textfield is the output of the final process, not the intermediate stuff. But I'm not sure how to parse console output or if console output is even parse-able once there's no more console? (i.e. the app has been full compiled and packaged and isn't being run from XCode any longer.)
When I was trying to figure this out, I saw lots of how-tos about converting stdout and stderr to a file, and I managed to extrapolate that to display it in the text field. But do I need to do this to work with it?
Second question: One of the pieces of data I need to work with is buried in fairly intricate line of text, and I'm unsure of the most efficient way of extracting it (and from there, isolating the first 8 characters of it, which is all I need)
Right now, what I have is this:
func parseOutput() {
let outputLog = outputDisplay.string
let outputLineArray = outputLog.split { $0.isNewline }
// filter by a keyword, which is a unique word that won't be
// found anywhere else in the log, preceding the data I actually need
// data I need will be Keyword == DataINeed
let outputLineElement = outputLineArray.filter { $0.contains("keyword") }
// convert the single array element that is the entire line into a string
let outputLineString = outputLineElement.joined()
// split the string into a new array separated by whitespaces
let singleLineArray = outputLineString.split(separator: " ")
// get the last part of that array, which is the data I actually need
let dataINeed = singleLineArray.last
// get the first 8 characters of that data and convert the substring to a string
dataFirst8 = String(dataINeed!.prefix(8))
}
Surely there has to be a less clumsy and repetitive way of doing this?