0

how do i transfer the contents of a string array to an int array in relation to my code below:

string[] sample= { "J♦", "3♦", "4♥", "Q♦", "9♥" };

convert(sample)

void sample(string[] straight)

int[] straight2 = new int[straight.Length];

 for (int i = 0; i < straight.Length; i++)
            {
                if (straight[i].StartsWith("J"))
                    straight2[i] = int.Parse("11"); //works fine
            }
            for (int i = 0; i < straight.Length; i++)
            {
                if (straight[i].StartsWith("Q"))
                    straight2[i] = int.Parse("12"); //works fine
            }


            for (int i = 0; i < straight.Length; i++)
            {
                straight2[i]=int.Parse(straight[i].Substring(0,1)); // ERROR: INPUT STRING NOT IN CORRECT FORMAT
            }

So i should have (11,3,4,12,9) //just the numbers. i don't want to include the suits (♦, ♥)

Please help

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by balrogf
0

Check what is the encoding type of your project. The suits above you have given are Unicode, I think, so it could be a problem with that.

0

got it now. just have to repeat my code for 2-10. thanks anywa

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.