-1

Can you suggest a short way on how to separate the user input with a semicolon, and the store it into an array.

The line when a user is entering words should look like this.

First;Second;Third;Forth
4b0
  • 21,981
  • 30
  • 95
  • 142
Josh
  • 187
  • 3
  • 13
  • 3
    user is inputting only words or numbers or what would be pattern? please explain more – Neel Oct 07 '14 at 04:33
  • every word/string that the user type will be separated by a semicolon and not with space – Josh Oct 07 '14 at 04:38
  • 1
    Also have look on http://stackoverflow.com/questions/3601465/string-split-vs-regex-split , this for making a choice between available options. – Arindam Nayak Oct 07 '14 at 04:48

2 Answers2

5

Assuming the user input is placed in raw_input variable

string[] input = raw_input.Split(';');
Diligent Key Presser
  • 4,183
  • 4
  • 26
  • 34
  • FYI- The String.Split method has few limitations. For example, it does not support splits on duplicate delimiters such as double pipe (||) characters, double tildes (~~), or double colons (::). – Arindam Nayak Oct 07 '14 at 04:47
  • @ArindamNayak Thank you for the tip, but the question was about a single delimiter – Diligent Key Presser Oct 07 '14 at 04:53
2

You can use Regex to split input, like following.

string input = "First;Second;Third;Forth";
string[] results = System.Text.RegularExpressions.Regex.Split(input,";");
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48