Wednesday 15 September 2010

ios - How to identify whether a number is a UPC code or just simple number ? is there any particular format to identify a UPC code? -


Is there any format we can use to identify the number of digits only for the UPC code?

I have some purpose-coded codes that allow a user to check a valid urp or ean barcode Confirms. It supports the UPC, ISBN, and EAN (8, 13, and 14).

If you have a number, then use this method to convert it to a string first. This method assumes that the barcode string can contain only 0-9 digits or one x (some ISBN can be x in barcode).

  - (BOOL) Valid Barcode: (NSString *) code {int len ​​= [code length]; Switch (lane) {Case 8: // EAN-8 {int check = [code intForDigitAt: 7]; Int val = (10 - (([code intForDigitAt: 1] + [code intForDigitAt: 3] [code intForDigitAt: 5] ([code intForDigitAt: 0] + [code intForDigitAt: 2] [code intForDigitAt: 4] + [code IntForDigitAt: 6]) * 3)% 10))% 10; Return check == vine; } Case 10: ISIN {Int Check = [Code Integrated At: 9]; Int sum = 0; For (int i = 0; i   

This uses the classification method I added to NSString :

  - (int) intForDigitAt: ( NSUInteger Index {unichar ch = [Self Character Asset Index: Index]; If (cac; = '0' and & amp;; CH & lt; = '9') {return CH - '0'; } And return 0; }    

No comments:

Post a Comment