I create an NSURLRequest and an NSURLConnection object and collect data in an NSMutableData instance. I then create an NSString from the downloaded data and get the directory listing of an ftp server that looks something like this:
drwx--x--x 13 username username 4096 Feb 5 17:43 .
drwx--x--x 13 username username 4096 Feb 5 17:43 ..
drwxr-x--- 14 username 99 4096 Feb 1 16:55 public_html
I’m guessing there is some standard way of parsing this data, but I have had no luck on google.
So my question is, what is the best way of getting this data into some manageable object?
You could use NSScanner to chop up the string. That’s probably the easiest option.
Alternatively, if those are tabs separating the values, you could split it up using the
componentsSeparatedByString:method of NSString (which returns an array), and just do it in several nested loops. So first split it by @”\n”, then split each line by @”\t”, and so on.Or if the spacing of the values in each line is always consistent, you could grab each value using the
substringWithRange:method of NSString.Or, if you’re comfortable with regular expressions, NSRegularExpression is another option.