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?

2
  • Why do you need to split it by \r\n0? Can't you use \r\n? Commented Apr 17, 2015 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. Commented Apr 17, 2015 at 10:27

1 Answer 1

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.