码迷,mamicode.com
首页 > Windows程序 > 详细

C#控制台基础 用字符分割字符串,删除空白项

时间:2016-10-07 17:40:06      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:

1、不删空白项

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication2
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string number = "0,,1..2,,3;;456789";
14             string[] strs = number.Split(new char []{,,.,; });
15             foreach (var item in strs)
16             {
17                 Console.WriteLine(item);
18             }
19             Console.ReadKey();
20         }
21 
22     }
23 
24 }

 

2、效果

技术分享

 

 

 

1、删除空白项的代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication2
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string number = "0,,1..2,,3;;456789";
14             string[] strs = number.Split(new char []{,,.,; },StringSplitOptions.RemoveEmptyEntries);
15             foreach (var item in strs)
16             {
17                 Console.WriteLine(item);
18             }
19             Console.ReadKey();
20         }
21 
22     }
23 
24 }

 

 

2、效果

技术分享

C#控制台基础 用字符分割字符串,删除空白项

标签:

原文地址:http://www.cnblogs.com/jinlingzi/p/5936141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!