Skip to main content
dedenting for better readibility
Source Link
Caridorc
  • 27.6k
  • 7
  • 54
  • 135

I have made a funtion to compare text files line by line, where timestamps and jobnumbers are replaced for a identical string. By lack of experience I'm not sure if this is the best way to do this.

            if (row < comparedFile.Count)
            {
                var regexJobNumber = @"([0-9]{4})";
                var regexTimeStamp = @"([0-9]{8}_[0-9]{6})";
                var input = line;
                var removeTimestamp = Regex.Matches(input, regexTimeStamp).Cast<object>().Aggregate(input, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
                var removeJobnumber = Regex.Matches(removeTimestamp, regexJobNumber).Cast<object>().Aggregate(removeTimestamp, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));
                

                var input2 = comparedFile[row];
                var removeTimestamp2 = Regex.Matches(input2, regexTimeStamp).Cast<object>().Aggregate(input2, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
                var removeJobnumber2 = Regex.Matches(removeTimestamp2, regexJobNumber).Cast<object>().Aggregate(removeTimestamp2, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));

                if (!removeJobnumber.Equals(removeJobnumber2))
                {
                   var rowcount = row + 1;
                   differenceList.Add("Difference found on rownumber: " + rowcount);
                }
                row++;
            }

I have made a funtion to compare text files line by line, where timestamps and jobnumbers are replaced for a identical string. By lack of experience I'm not sure if this is the best way to do this.

            if (row < comparedFile.Count)
            {
                var regexJobNumber = @"([0-9]{4})";
                var regexTimeStamp = @"([0-9]{8}_[0-9]{6})";
                var input = line;
                var removeTimestamp = Regex.Matches(input, regexTimeStamp).Cast<object>().Aggregate(input, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
                var removeJobnumber = Regex.Matches(removeTimestamp, regexJobNumber).Cast<object>().Aggregate(removeTimestamp, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));
                

                var input2 = comparedFile[row];
                var removeTimestamp2 = Regex.Matches(input2, regexTimeStamp).Cast<object>().Aggregate(input2, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
                var removeJobnumber2 = Regex.Matches(removeTimestamp2, regexJobNumber).Cast<object>().Aggregate(removeTimestamp2, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));

                if (!removeJobnumber.Equals(removeJobnumber2))
                {
                   var rowcount = row + 1;
                   differenceList.Add("Difference found on rownumber: " + rowcount);
                }
                row++;
            }

I have made a funtion to compare text files line by line, where timestamps and jobnumbers are replaced for a identical string. By lack of experience I'm not sure if this is the best way to do this.

if (row < comparedFile.Count)
{
    var regexJobNumber = @"([0-9]{4})";
    var regexTimeStamp = @"([0-9]{8}_[0-9]{6})";
    var input = line;
    var removeTimestamp = Regex.Matches(input, regexTimeStamp).Cast<object>().Aggregate(input, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
    var removeJobnumber = Regex.Matches(removeTimestamp, regexJobNumber).Cast<object>().Aggregate(removeTimestamp, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));
    

    var input2 = comparedFile[row];
    var removeTimestamp2 = Regex.Matches(input2, regexTimeStamp).Cast<object>().Aggregate(input2, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
    var removeJobnumber2 = Regex.Matches(removeTimestamp2, regexJobNumber).Cast<object>().Aggregate(removeTimestamp2, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));

    if (!removeJobnumber.Equals(removeJobnumber2))
    {
       var rowcount = row + 1;
       differenceList.Add("Difference found on rownumber: " + rowcount);
    }
    row++;
}
Source Link

Regex in combination with file compare

I have made a funtion to compare text files line by line, where timestamps and jobnumbers are replaced for a identical string. By lack of experience I'm not sure if this is the best way to do this.

            if (row < comparedFile.Count)
            {
                var regexJobNumber = @"([0-9]{4})";
                var regexTimeStamp = @"([0-9]{8}_[0-9]{6})";
                var input = line;
                var removeTimestamp = Regex.Matches(input, regexTimeStamp).Cast<object>().Aggregate(input, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
                var removeJobnumber = Regex.Matches(removeTimestamp, regexJobNumber).Cast<object>().Aggregate(removeTimestamp, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));
                

                var input2 = comparedFile[row];
                var removeTimestamp2 = Regex.Matches(input2, regexTimeStamp).Cast<object>().Aggregate(input2, (current, Match) => Regex.Replace(current, regexTimeStamp, "<TimeStamp>"));
                var removeJobnumber2 = Regex.Matches(removeTimestamp2, regexJobNumber).Cast<object>().Aggregate(removeTimestamp2, (current, Match) => Regex.Replace(current, regexJobNumber, "<JobNummer>"));

                if (!removeJobnumber.Equals(removeJobnumber2))
                {
                   var rowcount = row + 1;
                   differenceList.Add("Difference found on rownumber: " + rowcount);
                }
                row++;
            }