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

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.