我想将用户输入字符串拆分为2个字符串。
string userinput = Console.ReadLine();
我希望当用户输入“ open google.com”时将其分为2个字符串,例如:
string userinput1 = "open";
string userinput2 = "google.com";
并且,如果用户输入的内容类似于“ open google.com example”,则“ example”一词将被忽略并且不会存储在任何字符串中:D
我希望你能帮助我。
String.Split
是有用的。
string userinput = Console.ReadLine();
char[] delim = new char[]{ ' ' };
string[] splitted = userinput.Split(delim);
string userinput1 = splitted[0];
string userinput2 = splitted[1];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句