• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/Mjk1

Calculate the checksum for Bankgiro or Postgiro ORC-numbers by using 10-modul.


0
366 0 0 0 0 0

public class BgcOcrCheckSum
{
    public static string GetBgcCheckSumFromOcrString(string ocrWithChecksum)
    {
        return string.IsNullOrEmpty(ocrWithChecksum) ? string.Empty : ocrWithChecksum.Substring(ocrWithChecksum.Length - 1);
    }


    public static long CalculateBgcOcrChecksum(string ocrWithoutChecksum)
    {
        long lngSum = 0;

        for (var lngPos = 0; lngPos < ocrWithoutChecksum.Length; lngPos++)
        {
            var lngTemp = int.Parse(ocrWithoutChecksum[lngPos].ToString()) * ((lngPos % 2) + 1);

            if (lngTemp > 9)
                lngTemp = lngTemp - 9;

            lngSum = lngSum + lngTemp;
        }

        var checkNumber = (10 - (lngSum % 10)) % 10;

        return checkNumber;
    }


    public static bool VerifyBgcOcrCheckSum(string ocrWithChecksum)
    {
        var checkSum = GetBgcCheckSumFromOcrString(ocrWithChecksum);

        var stringWithoutSum = ocrWithChecksum.Substring(0, ocrWithChecksum.Length - 1);

        var calculatedCheckSum = CalculateBgcOcrChecksum(stringWithoutSum);

        return calculatedCheckSum == long.Parse(checkSum);
    }
}

Share: twitter | facebook   Action: used | fork | flag

algorithm

Mark 'algorithm' tag as 'like'

Mark 'algorithm' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

ocr

Mark 'ocr' tag as 'like'

Mark 'ocr' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
September 29, 2010 1:15 PM
edited October 07, 2010 1:57 PM

Fork

 Calculate the checksum for Bankgiro or Postgiro ORC-numbers by using 10-modul. -  @fredrikn Wednesday 29, 2010 1:15 PM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010