C# 字符串转换为列表:将 "1;2;3" 转换为 List<string> {1, 2, 3}
要将字符串 str="1;2;3" 转换为 Listcsharp\nusing System;\nusing System.Collections.Generic;\n\nclass Program\n{\n static void Main()\n {\n string str = "1;2;3";\n List<string> strlist = new List<string>(str.Split(';'));\n \n foreach (string s in strlist)\n {\n Console.WriteLine(s);\n }\n }\n}\n\n\n输出结果为:\n\n\n1\n2\n3\n\n\n在上面的示例中,首先使用 Split 方法将字符串 str 分割为多个子字符串。Split 方法使用分号 ';' 作为分隔符,返回一个字符串数组。然后,我们将该字符串数组传递给 List
原文地址: https://www.cveoy.top/t/topic/pZln 著作权归作者所有。请勿转载和采集!