Hey guys, I was wondering if you knew a of an equivalent of 'substr' for integers. So for example, if a user input a credit card / debit card number and you want to detect what kind of card it is based on the first number the integer begins with (ex - Master Card starts for '5', Visa begins within '4' and etc) how would you do that? Thank you
salem c's suggestion works for using "substr()", but if all you want is the first number then cardNum[0] is all you need. Just keep in mind this is a "char" not an "int".
Just in case you keep that Master Card and Visa numbers as integer not as a string (recommended), to pick a single digit / and % (integer divide and modulo) may help. 5432 / 1000 = 5. Or the 2nd digit from the RHS: (5432 % 100) / 10 = 3
integers are not stored in base 10 inside computers so no, there is no 'get the digit' feature because the 'digit' is a bit, not a base 10 digit. If you want the bit, you can have that, or a subset of them, all that is easy. You have to do the math as Mike showed above, or similar, or convert it to string or always have it as a string.
Ok sounds good thank you guys for all the help. I'm going to play around with it and see what I can come up with. I think I'll originally try to use ints and then go on to strings and see what I can come up with. Thank you again for all the help.