Question

How do I use the Console.Readline().Split() to split anything else than letters(, * & % .). Instead of inputting every one of the possible characters in the Split(), is there an easier way to do this?

Was it helpful?

Solution

string line = Console.ReadLine();
string[] segments = Regex.Split(input: line, pattern: "\W");

OTHER TIPS

Split takes params which means the parameter list is turned into an array argument.

You can pass in a list of strings to split by - for example, with the characters you have given:

var line = Console.ReadLine();
var segements = line.Split(' ', ',', '*', '&', '%', '.');

Edit: The regular expression answers are good, if thats what you mean - but if you only want the specified characters then this is better - because it wont be affected by non-English characters.

Console.Readline() return String, so use the Split is just like usual Split

You can use Split with regex

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top