1

I have a log-file, example:
000124 14:44:54:370 Text IO Text Text Text
text text text

text text text

000125 14:44:54:370 Text IO Text Text Text text text text

texttext
000126 14:44:54:370 Text IO Text Text Text

I split this text into an array using this code:

let path = NSBundle.mainBundle().pathForResource("log file", ofType: "log")
var text = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)!
var textArr = text.componentsSeparatedByString("\r\n0")
var lines = textArr.count

But sometimes the log-file gets very big and this happens:
099999 14:44:54:370 Text IO Text Text Text
text text text

text text text

100000 14:44:54:370 Text IO Text Text Text
100001 14:44:54:370 Text IO Text Text Text

What I would like to do is to have a code that does something like this:

var textArr = text.componentsSeparatedByString("\r\n0" OR "\r\n1")

Would it be possible? Or any other solutions for my problem?

aurelius
  • 448
  • 7
  • 23
  • Why do you need to split it by `\r\n0`? Can't you use `\r\n`? – padarom Apr 17 '15 at 10:24
  • I´m sorry, it was a bad example of the log file, I updated it now. \r\n0 is the only repeating thing that I could split it on to get the new log-line. – aurelius Apr 17 '15 at 10:27

1 Answers1

0

I "solved" it by doing this, perhaps not the smartest way but it seems to be working fine:

var text = String(contentsOfFile: path!, encoding: NSUTF8StringEncoding, error: nil)!
var textArr = text.componentsSeparatedByString("\r\n0")
var lines = textArr.count
var textArrLarge = textArr[lines-1].componentsSeparatedByString("\r\n1")
var linesLarge = textArrLarge.count
var linesTot = lines + linesLarge-1
var textArrTot = textArr + textArrLarge
textArrTot.removeAtIndex(lines)
aurelius
  • 448
  • 7
  • 23