C# Array Problem
-
Hey, wonder if any1 can help me, its a fairly simple issue to deal with so im told but ive spent ages trying to work this out, but havnt got anywhere.:(( So was wondering if sum1 could lend a hand. Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word I know it seems alot to ask, but id really appreciate it if sum1 could provide some example I could follow in order for me to get mine working... Thanks in advance Neptune
-
Hey, wonder if any1 can help me, its a fairly simple issue to deal with so im told but ive spent ages trying to work this out, but havnt got anywhere.:(( So was wondering if sum1 could lend a hand. Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word I know it seems alot to ask, but id really appreciate it if sum1 could provide some example I could follow in order for me to get mine working... Thanks in advance Neptune
Random rand = new Random();
string[] somestrings = { "Hello", "World", "From", "An", "Array" };
string randString = somestrings[rand.Next(somestrings.Length - 1)]; // get a random string from the array
char[] characters = randString.ToCharArray(); // get an array of the characters from this particular stringregards
-
Hey, wonder if any1 can help me, its a fairly simple issue to deal with so im told but ive spent ages trying to work this out, but havnt got anywhere.:(( So was wondering if sum1 could lend a hand. Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word I know it seems alot to ask, but id really appreciate it if sum1 could provide some example I could follow in order for me to get mine working... Thanks in advance Neptune
Before you start writing an ounce of code, make sure you have a game plan (i.e. psuedocode or flowchart) that expresses your logic. Once you're fairly certain your logic is correct, it'll be pretty easy to convert it to C# (or any other language). You could start by posting your logic and we'd be happy to help you refine/verify it. /ravi
My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
Hey, wonder if any1 can help me, its a fairly simple issue to deal with so im told but ive spent ages trying to work this out, but havnt got anywhere.:(( So was wondering if sum1 could lend a hand. Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word I know it seems alot to ask, but id really appreciate it if sum1 could provide some example I could follow in order for me to get mine working... Thanks in advance Neptune
I would do something like this. public bool isMatch() { bool Matches = false; string[] asCompare = new string[4]; asCompare.SetValue("First0", 0); asCompare.SetValue("Second1", 1); asCompare.SetValue("Third2", 2); asCompare.SetValue("Fourth3", 3); Random ran = new Random(); int iVal = ran.Next(asCompare.Length - 1); string sValue = asCompare[iVal]; char[] chars = sValue.ToCharArray(); string sCharTracker = ""; for (int i = 0; i < chars.Length; i++) { sCharTracker = chars[i].ToString(); //Matches = //you would probably do your compare with a method call here// } return Matches;//This will be if it matches or not// }
-
Hey, wonder if any1 can help me, its a fairly simple issue to deal with so im told but ive spent ages trying to work this out, but havnt got anywhere.:(( So was wondering if sum1 could lend a hand. Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word I know it seems alot to ask, but id really appreciate it if sum1 could provide some example I could follow in order for me to get mine working... Thanks in advance Neptune
neptune2k wrote:
Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word
That's a one-liner. :)
char[] chars = (new string[] { "some","words","in","an","array" })[(new Random()).Next(5))].ToCharArray();
--- b { font-weight: normal; }
-
Hey, wonder if any1 can help me, its a fairly simple issue to deal with so im told but ive spent ages trying to work this out, but havnt got anywhere.:(( So was wondering if sum1 could lend a hand. Basically ive an array of strings and i want to randomly select a word out of this array Once the word is selected i then need to split the word into separate characters, so I can check the users input against each letter until they finally guess the word I know it seems alot to ask, but id really appreciate it if sum1 could provide some example I could follow in order for me to get mine working... Thanks in advance Neptune