Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对于控制台应用程序的启动方式static void Main(string[] args),假设参数传递如下:
static void Main(string[] args)
你好世界a,b,c,d
从 agrs 中获取 a、b、c 和 d 的最佳方法是什么(没有空格和逗号)?
string[] s = args[0].Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
var elements = args[0].Split(',').Select(s => s.Trim());
您可以使用Trim()删除空格和Replace()替换逗号分隔值。
Trim()
Replace()