質問

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?

役に立ちましたか?

解決

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top