Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

basic help, new to this

programTomprogramTom Posts: 33Member
Hello

Im talking about a console app here.
I the user to be able to write a series of words at the command line.
Eg. Enter words -> dog cat hat

Then i just want to read those words into an array.
So my array would be
wordsArray[0] = dog
wordsArray[1] = cat
wordsArray[2] = hat

I just wondering how to do this.

Comments

  • IDKIDK Posts: 1,784Member
    : Hello
    :
    : Im talking about a console app here.
    : I the user to be able to write a series of words at the command line.
    : Eg. Enter words -> dog cat hat
    :
    : Then i just want to read those words into an array.
    : So my array would be
    : wordsArray[0] = dog
    : wordsArray[1] = cat
    : wordsArray[2] = hat
    :
    : I just wondering how to do this.
    :
    :

    Use string.separate, or something similar. I can't remember the name.
  • programTomprogramTom Posts: 33Member
    : : Hello
    : :
    : : Im talking about a console app here.
    : : I the user to be able to write a series of words at the command line.
    : : Eg. Enter words -> dog cat hat
    : :
    : : Then i just want to read those words into an array.
    : : So my array would be
    : : wordsArray[0] = dog
    : : wordsArray[1] = cat
    : : wordsArray[2] = hat
    : :
    : : I just wondering how to do this.
    : :
    : :
    :
    : Use string.separate, or something similar. I can't remember the name.
    :
    hi i dont really know wot u mean...but this is what ive done..and so far its not working

    [code]
    int wordindex = 0;
    int inputchar = -1;
    message = "Command -> ";
    userCommand = new string[3];
    //while (userCommand[0] != "quit")
    //{
    Console.Write(message);
    while ((inputchar=Console.Read()) != -1)
    {
    if (inputchar == ' ')
    {
    wordindex++;
    }
    else if (inputchar != ' ')
    {
    userCommand[wordindex] += inputchar;
    //here im just checking to see what is being //assigned to the usercommand array...its showing a series of numbers
    Console.WriteLine(inputchar);
    }
    }

    Console.WriteLine(command.Execute(player, userCommand));
    //}

    [/code]

    i didnt use that string.separate,,,thing i dont really know what it is?

  • IDKIDK Posts: 1,784Member
    : : : Hello
    : : :
    : : : Im talking about a console app here.
    : : : I the user to be able to write a series of words at the command line.
    : : : Eg. Enter words -> dog cat hat
    : : :
    : : : Then i just want to read those words into an array.
    : : : So my array would be
    : : : wordsArray[0] = dog
    : : : wordsArray[1] = cat
    : : : wordsArray[2] = hat
    : : :
    : : : I just wondering how to do this.
    : : :
    : : :
    : :
    : : Use string.separate, or something similar. I can't remember the name.
    : :
    : hi i dont really know wot u mean...but this is what ive done..and so far its not working
    :
    : [code]
    : int wordindex = 0;
    : int inputchar = -1;
    : message = "Command -> ";
    : userCommand = new string[3];
    : //while (userCommand[0] != "quit")
    : //{
    : Console.Write(message);
    : while ((inputchar=Console.Read()) != -1)
    : {
    : if (inputchar == ' ')
    : {
    : wordindex++;
    : }
    : else if (inputchar != ' ')
    : {
    : userCommand[wordindex] += inputchar;
    : //here im just checking to see what is being //assigned to the usercommand array...its showing a series of numbers
    : Console.WriteLine(inputchar);
    : }
    : }
    :
    : Console.WriteLine(command.Execute(player, userCommand));
    : //}
    :
    : [/code]
    :
    : i didnt use that string.separate,,,thing i dont really know what it is?
    :
    :

    This is what I mean:
    [code]
    Console.Read(message);
    wordlist = message.split(' ');
    [/code]
    Look at the string functions if you can't find split as I don't know if it's named that.
Sign In or Register to comment.