gipasoft

Calcolare CheckDigit EAN13

Jun 1st, 2013
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. public static int getEAN13CheckSum(string strData)
  2. {
  3.     int iLen = strData.Length;
  4.     int i = 0;
  5.     int result = 0;
  6.     int getSum = 0;
  7.     string parseStr = strData.Trim();
  8.     string CharInt = "";
  9.     while (parseStr.Length != 0) // (iLen - 1))
  10.     {
  11.         CharInt = ClsReusable.Left(parseStr, 1); // Len: 1 - Line Size ( Trim first two character )
  12.         parseStr = ClsReusable.Right(parseStr, parseStr.Length - 1);
  13.  
  14.         if ((i % 2) == 0)
  15.             result = Convert.ToInt32(CharInt) * 1; //Even num Position
  16.         else
  17.             result = Convert.ToInt32(CharInt) * 3; //Odd num Position
  18.  
  19.         i = i + 1;
  20.         getSum = result + getSum;
  21.         result = 0;
  22.     }
  23.     if (getSum.ToString().Length == 1) { return (getSum - 10); }
  24.  
  25.     if (getSum.ToString().Length > 1)
  26.     {
  27.         return (10 - (getSum % Convert.ToInt32(ClsReusable.Left(getSum.ToString(), getSum.ToString().Length - 1) + "0")));
  28.     }
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment