zoukankan      html  css  js  c++  java
  • C# 如何用多个字符串来切分字符串并去除空格

    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Text;  
    5. using System.Data;  
    6.   
    7. namespace Study  
    8. {  
    9.     public static class Program3  
    10.     {  
    11.         static void Main(string[] args)  
    12.         {  
    13.             Proccess(@"13212345671,13312345672,  13412345674  
    14.             13212345674,");  
    15.             Proccess("");  
    16.             Proccess(null);  
    17.             Console.Read();  
    18.         }  
    19.   
    20.         public static void Proccess(string str)   
    21.         {  
    22.             //双问号保证 null 值不会异常  
    23.             //StringSplitOptions.RemoveEmptyEntries 会移除 string.Empty 空串, 但对于空格无能为力  
    24.             //' '将按空格来切分,所以不再有空格出现  
    25.             string[] arr = (str ?? string.Empty).Split(new char[] { ',', '\t', '\n', ' ' }, StringSplitOptions.RemoveEmptyEntries);  
    26.             Console.WriteLine("本次切分后数组的长度为:{0}", arr.Length);  
    27.             int i = 1;  
    28.             foreach (string s in arr)  
    29.             {  
    30.                 Console.WriteLine("{0}:{1}", (i++).ToString(), s);  
    31.             }  
    32.         }  
    33.     }  
    34. }  
     
  • 相关阅读:
    Golang的select多路复用以及channel使用实践
    golang-goroutine和channel
    golang类型转换小总结
    golang之终端操作,文件操作
    golang之结构体和方法
    golang基础之三-字符串,时间,流程控制,函数
    Linux Keepliaved安装
    Git打标签、还原到具体标签版本代码
    Git复制已有分支到新分支开发
    记一次内存分析
  • 原文地址:https://www.cnblogs.com/just09161018/p/4605333.html
Copyright © 2011-2022 走看看