数组与字符串互转

来源:互联网 发布:中国石油大学网络教育 编辑:程序博客网 时间:2024/06/14 01:15

数组与字符串互转


        static void Main(string[] args)        {            string testStr = "1,6,7,8,9,五,";//字符串格式数组 测试数据            string[] unitIds = testStr.Split(',');//将字符串格式数组转化为数组            string result = string.Join(",", unitIds);//将数组转化为字符串            Console.WriteLine(result);            Console.WriteLine("------------------------\n");            //筛选int类型数据            int id;            foreach (string item in unitIds)            {                if (string.IsNullOrEmpty(item)) continue;                if (int.TryParse(item, out id))                    Console.WriteLine(id);            }                    }







0 0
原创粉丝点击