- Where Developers Learn, Share, & Build Careers


I'm parsing a log file to make a report, but String.IndexOf () On some lines, using C # is the easiest to understand with some code here.

  string line = "Jun 29 14:34:19 localhost axis 2_http_server: CEF: 0 | Aopitiaiaks | IRIS | 4.1.0.1664.2839 | Eddie 214030000301-2610017 | 114 | Sdike_sisisis | 4 | time = 1340 9 80459 comp = 10 compinfo = = 8 result = user = admin thread = 1305: 1 9 62 msg = ation = 0.00, Face collar = 11.49 hr face ICAO compliant, inter-pupil capture distance = 140.00 LEFT_uid = -1, blacklist = 0 No match found on right eye (database is empty) RIGHT_uid = -1, blacklist = 0 Capture successfully completed - send SOAP reply Done. " Int ctIndex = line.IndexOf ("CaptureTime ="); Return ctIndex;   

Expected: -1
Real: 11

This would be just about 2 lines for a gig of log files is.

The actual implementation method

  private Taimspen parse calibration (string line) {int ctIndex = line.IndexOf ( "CaptureTime ="); CtIndex = ctIndex + "CaptureTime =" Length; Int endIndex = line.IndexOf ("", ctIndex); String sDuration = line .Substring (ctIndex, endIndex - ctIndex); Long Term; If (long! Try purse (period, duration)) {console. Virus line ("error parsing period"); Return TimeSpan.Zero; } Period * = 1000; Timespace transmitter = new timespan (period * 1000); Return tsDuration; }   

Try line feeding code

  {streamReader sr = new streamrider (file path); String line = sr.ReadLine (); While (line! = Null) {time span ts = parcuration (line); Line = sr.ReadLine (); } Hold (Exception Pre) {} Finally {sr.close ();}    

Your method does not check that ctIndex equals 1. Then you are adding the length of "CaptureTime =" to ctIndex, then giving priority to a substrings.

I suspect that your code will not work properly for log messages in its current state, in which there is no CaptureTime = value for those reasons, is it functional behavior?

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -