c# - String.indexOf returns non-negative index when search string does not occur in string -
I am parsing some log files to create a report, but Expected: -1 This would only be about 2 lines for a gig of log files is. Actual implemented method Try line feeding code 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? String.IndexOf () On some lines, using C # is the easiest to understand with some code here.
string line = "June 29 14:34:19 localhost axis 2_http_server: CEF: 0 | AOPTix | IRIS | 4.1.0.1664.2839 | AD 214030000301-2610017 | 114 | SDK_ACCACS | 4 | Time = 1340 9 80459 comp = 10 compinfo = = 8 results = = User = admin thread = 1305: 1 9 62 msg = ation = 0.00, face collar = 11.49 HR face ICAO compliant, inter-disciple distance = 140.00 Capture 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;
Real: 11
Personal Timespace Pars 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; }
{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 ();}
Comments
Post a Comment