Skip to content

Reading Digits from String ... HELP!!!

Juan Castillo

Asked Feb 13, 2007, 2:26 PM EST1 answer
Share
LinkedInX

Hi guys,

I'm kind of new at this and I seem to have very small experience on the C# language... I hope someone can help me out.

I need to built a console application that will read a card number with the following format ( 999-999999-9). The program needs to identify the la number which the verification digit . With the digit it determine if the card number is valid or not.

I started out using a long variable but it wont accept the "-"  so i decided to use a string which it can take the entire statement as the software requires. How i can read the digits ignoring the "-" and storing the last number on a seperate variable?


Thanks

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You could do something like this (assuming you have the string in a variable called 'code'):

    string[] digits = code.Split('-');
    int first = int.Parse(digits[0]);
    int second = int.Parse(digits[1]);
    int third = int.Parse(digits[2]);
    0