Is there a way i can represent a large string as an integer or something simular in size in order to indentify any changes?

I'm looking for a way to validate a long string and see if its changed, so lets say for example that  have the following string.

"FileCodeImageScreencast2020"

Now lets say that this was changed to

"FileCodeImageScreencatt3030"

I'm looking for an easy way to identify if this has changed. But the key thing here is size ideally im looking for an integer style result to identify if its changed, the reason being is because in the real situation i have 10million rows, all around 5000 characters in length and this is why i cant do simple string compares i.e. not enough memory on server, so i need to store the states of each row as something smaller in size.

So to summerise is there a way i can represent a large string as an integer or something simular in size in order to indentify if any changes have taken place?

Any working examples would be greatly appreciated

Thanks
Webbo
Webbo_1980Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NeuropsykopatCommented:
Use a MD5 hash for each string

  public string GetMD5Hash(string input)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();
            return password;
        }
Dave BaldwinFixer of ProblemsCommented:
Typical file signatures are done with MD5 and SHA1.  MD5 output is 32 characters and I don't know what SHA1 is off the top of my head.  http://en.wikipedia.org/wiki/Comparison_of_cryptographic_hash_functions
hackpinCommented:
Try to convert string to byte of arrays and you can also use it to compare characters if there's changes made even if the string is in the same length.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Asim NazirCommented:
Is this data stored in DB? Why don't you use Triggers? This way you can always check whether row exists in Auduit table and thats it.
What you say?
Webbo_1980Author Commented:
Thanks
Hi asimnazir123, triggers arnt an option im afrad, has too many performance issues, thus the reason im storing everything into memory, and im not looking to change this approach at thsi stage.

Anyway i'm trying MD5 and SHA1 options as we speak and will confirm suitability shortly.

deightonprogCommented:
the problem with the hash is that two different strings can have the same has, so I would say that you cannot represent such a string as an integer.
Carl TawnSystems and Integration DeveloperCommented:
MD5 Hash is a little overkill if you simply want to check if the string has changed. Simply calling GetHashCode() on the string object should suffice in this scenario:
            string wibble = "Hello World";
            Console.WriteLine(wibble.GetHashCode());

            wibble = "HEllo World";
            Console.WriteLine(wibble.GetHashCode());

            wibble = "Hello World";
            Console.WriteLine(wibble.GetHashCode());

            wibble = "HEllo WOrld";
            Console.WriteLine(wibble.GetHashCode());

            Console.ReadLine();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Asim NazirCommented:
One other way can be to Serialize and Deserialize strings, then you can compare them either using Deep compare at http://comparenetobjects.codeplex.com/ or using standard .Net library.
Webbo_1980Author Commented:
Thanks all MD5 does work, but yes gethashcode is so much simplier

Thanks
Webbo
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.