2

I need to do the following in C#. I have string "expectedCopyright" that is predefined as "Copyright (C) My Company X-2013. All rights reserved" . X can vary in the different cases.
I need to check my files actual copyright string and to compare it with that given one, but excluding the 'X' (first year of creation) because it will be different for the different files.

Currently I've got the following:

string actualLegalCopyright = versionInfo.LegalCopyright;
xmlWriter.WriteElementString("Copyright_actual", actualLegalCopyright);
if (actualLegalCopyright != null)
{
    if (actualLegalCopyright.Contains(expectedCopyright) == true)
    {
        xmlWriter.WriteElementString("Copyright_test", "Pass");
        PassCountCpyr++;
    }
    else
    {
        xmlWriter.WriteElementString("Copyright_test", "Warning: Unexpected Values");
        WarnCountCpyr++;
    }
}
else
{
    xmlWriter.WriteElementString("Copyright_test", "Fail: No Values");
    FailCountCpyr++;
}

But that compares the whole string... which still contains 'X'. Possible I need to split the expected string on two pieces and to check for both of them? I would appreciate any other suggestions.

1 Answer 1

4
if (System.Text.RegularExpressions.Regex.IsMatch(
    actualLegalCopyright,
    @"Copyright \(C\) My Company [0-9]{4}-2013. All rights reserved"))

Will execute if the text matches with X being any 4-digit number, and an else will trigger if it doesn't.

Sign up to request clarification or add additional context in comments.

2 Comments

Omg, that worked perfectly well. :)) Thank you so much!. I also wanted to ask you if you know a way to actually use 'expectedCopyright' variable, because I'm expecting the content to change and I don't really want to modify the source every time :/ Currently I'm capturing it from an. xml file that is the only place where changes are introduced. Thanks :)
ok, I think I did it :) Thanks a lot again :) Have a lovely day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.