Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Array Problem

C# Array Problem

Scheduled Pinned Locked Moved C#
helpcsharpdata-structurestutorial
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    neptune2k
    wrote on last edited by
    #1

    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

    L R P G N 5 Replies Last reply
    0
    • N neptune2k

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 string

      regards

      1 Reply Last reply
      0
      • N neptune2k

        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

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • N neptune2k

          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

          P Offline
          P Offline
          Private_Void
          wrote on last edited by
          #4

          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// }

          1 Reply Last reply
          0
          • N neptune2k

            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

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            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; }

            1 Reply Last reply
            0
            • N neptune2k

              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

              N Offline
              N Offline
              neptune2k
              wrote on last edited by
              #6

              thanks guys, thats really helped, i get where i was going wrong now i know where to come in future if i hit any problems :)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups