String.Join 方法

平常工作中经常用到string.join()方法,在vs 2017用的运行时(System.Runtime, Version=4.2.0.0)中,共有九个(重载)方法。

//
// 摘要:
// Concatenates the members of a collection, using the specified separator between
// each member.
//
// 参数:
// separator:
// The string to use as a separator.separator is included in the returned string
// only if values has more than one element.
//
// values:
// A collection that contains the objects to concatenate.
//
// 类型参数:
// T:
// The type of the members of values.
//
// 返回结果:
// A string that consists of the members of values delimited by the separator string.
// If values has no members, the method returns System.String.Empty.
//
// 异常:
// T:System.ArgumentNullException:
// values is null.
public static String Join<T>(String separator, IEnumerable<T> values);
//
// 摘要:
// Concatenates the members of a constructed System.Collections.Generic.IEnumerable`1
// collection of type System.String, using the specified separator between each
// member.
//
// 参数:
// separator:
// The string to use as a separator.separator is included in the returned string
// only if values has more than one element.
//
// values:
// A collection that contains the strings to concatenate.
//
// 返回结果:
// A string that consists of the members of values delimited by the separator string.
// If values has no members, the method returns System.String.Empty.
//
// 异常:
// T:System.ArgumentNullException:
// values is null.
public static String Join(String separator, IEnumerable<String> values);
//
// 摘要:
// Concatenates the elements of an object array, using the specified separator between
// each element.
//
// 参数:
// separator:
// The string to use as a separator. separator is included in the returned string
// only if values has more than one element.
//
// values:
// An array that contains the elements to concatenate.
//
// 返回结果:
// A string that consists of the elements of values delimited by the separator string.
// If values is an empty array, the method returns System.String.Empty.
//
// 异常:
// T:System.ArgumentNullException:
// values is null.
public static String Join(String separator, params object[] values);
//
// 摘要:
// Concatenates all the elements of a string array, using the specified separator
// between each element.
//
// 参数:
// separator:
// The string to use as a separator. separator is included in the returned string
// only if value has more than one element.
//
// value:
// An array that contains the elements to concatenate.
//
// 返回结果:
// A string that consists of the elements in value delimited by the separator string.
// If value is an empty array, the method returns System.String.Empty.
//
// 异常:
// T:System.ArgumentNullException:
// value is null.
public static String Join(String separator, params String[] value);
//
// 摘要:
// Concatenates the specified elements of a string array, using the specified separator
// between each element.
//
// 参数:
// separator:
// The string to use as a separator. separator is included in the returned string
// only if value has more than one element.
//
// value:
// An array that contains the elements to concatenate.
//
// startIndex:
// The first element in value to use.
//
// count:
// The number of elements of value to use.
//
// 返回结果:
// A string that consists of the strings in value delimited by the separator string.
// -or- System.String.Empty if count is zero, value has no elements, or separator
// and all the elements of value are System.String.Empty.
//
// 异常:
// T:System.ArgumentNullException:
// value is null.
//
// T:System.ArgumentOutOfRangeException:
// startIndex or count is less than 0. -or- startIndex plus count is greater than
// the number of elements in value.
//
// T:System.OutOfMemoryException:
// Out of memory.
public static String Join(String separator, String[] value, int startIndex, int count);
//
// 参数:
// separator:
//
// value:
public static String Join(char separator, params String[] value);
//
// 参数:
// separator:
//
// value:
//
// startIndex:
//
// count:
public static String Join(char separator, String[] value, int startIndex, int count);
//
// 参数:
// separator:
//
// values:
public static String Join(char separator, params object[] values);
//
// 参数:
// separator:
//
// values:
//
// 类型参数:
// T:
public static String Join<T>(char separator, IEnumerable<T> values);

string.Join 重载方法详解

所以平常写方法的时候,基本上都覆盖了。

常用方法:separator以“,”为例。

string.Join(',',string[])   //字符','分割,拼接字符串数组

string.Join(',',List<string>)  //字符','分割,拼接字符串列表  

string.Join(",",string[])   //字符串“,”分割,拼接字符数组

string.Join(",",List<string>)  //字符串“,”分割,拼接字符数组

备注:vs2013中重载方法没有这么多,需注意。

C# string.join的更多相关文章

  1. BCL中String.Join的实现

    在开发中,有时候会遇到需要把一个List对象中的某个字段用一个分隔符拼成一个字符串的情况.比如在SQL语句的in条件中,我们通常需要把List<int>这样的对象转换为“1,2,3”这样的 ...

  2. c# String.Join 和 Distinct 方法 去除字符串中重复字符

    1.在写程序中经常操作字符串,需要去重,以前我的用方式利用List集合和 contains去重复数据代码如下: string test="123,123,32,125,68,9565,432 ...

  3. String.Join的巧用

    String.Join大大的方便了我们拼接字符串的处理. 1.普通用法:指定元素间的拼接符号 var ids = new List<int>(); for (int i = 0; i &l ...

  4. string.Join()的用法

    List<string> list = new List<string>(); list.Add("I"); list.Add("Love&quo ...

  5. string.join加引号

    columnsGen = string.Join(",", modelDictionary.Keys); valueGen = modelDictionary.Values.Agg ...

  6. String.Join 和 Distinct 方法 去除字符串中重复字符

    Qualys项目中写到将ServerIP以“,”分割后插入数据库并将重复的IP去除后发送到服务器进行Scan,于是我写了下面的一段用来剔除重复IP: //CR#1796870 modify by v- ...

  7. String.join()方法的使用

    String.join()方法是JDK1.8之后新增的一个静态方法,使用方式如下所示: String  result = String.join("-","java&qu ...

  8. 教你50招提升ASP.NET性能(二十三):StringBuilder不适用于所有字符串连接的场景;String.Join可能是

    (41)StringBuilder is NOT the answer for all string concatenation scenarios; String.Join could be 招数4 ...

  9. Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5

    linq to sql 的时候,有时候需要用到 先group  然后来个 aggregate 串连一下值, 但会总会出错,说不识别 aggregate 或者 string.join 方法 搜遍网络 一 ...

  10. string.Join和string.Concat的区别

    源自Difference between String.Join() vs String.Concat() With .NET 4.0, String.Join() uses StringBuilde ...

随机推荐

  1. python 管道 事件(Event) 信号量 进程池(map/同步/异步)回调函数

    ####################总结######################## 管道:是进程间通信的第二种方式,但是不推荐使用,因为管道会导致数据不安全的情况出现 事件:当我运行主进程的 ...

  2. ruby读取exce文件,使用roo---Gem

    module SEquipsHelper #设备台账,从excel文件读取信息 require 'roo' #require 'roo-xls' #读取excel文件 # SEquipsHelper. ...

  3. Linux拉你入门

    前言:为了做一个更优秀的程序猿,Linux是必不可少的,因此利用闲杂的时间来增加自己对Linux的认识 (一)关于Linux命令编(至于怎样安装vmvare这一个章节就先不介绍了) 1.基础命令 1. ...

  4. DirectX11 With Windows SDK--02 顶点/像素着色器的创建、顶点缓冲区

    前言 由于在Direct3D 11中取消了固定管线,要想绘制图形必须要了解可编程渲染管线的流程,一个能绘制出图形的渲染管线最少需要有这两个可编程着色器:顶点着色器和像素着色器. 本章会直接跳过渲染管线 ...

  5. HDU 1024(新最大子序列和 DP)

    题意是要在一段数列中求 m 段互不重合的子数列的最大和. 动态规划,用数组 num[ ] 存储所给数列,建二维数组 dp[ ][ ] , dp[ i ][ j ] 表示当选择了第 j 个数字( num ...

  6. Mac 键盘符号 及VSCode快捷键 说明

    Mac 键盘符号说明 ⌘ == Command ⇧ == Shift ⇪ == Caps Lock ⌥ == Option ⌃ == Control ↩ == Return/Enter ⌫ == De ...

  7. Python的参数类型

    参数类型: 1.必填参数,位置参数(positional arguments,官方定义,就是其他语言所说的参数) 2.默认值参数,非必传 3.可变参数,非必传,不限制参数个数,比如说给多个人发邮件,发 ...

  8. app-web 开发 追溯debug

    1.iphone5 运行vue项目时,方法格式:fun(){}这种格式容易不显示页面 2.vue未绑定上数据有可能是js文本过大,手机内存不足引起的 3.根据方法走向追溯debug 4.一定要用try ...

  9. Python7 - 面向对象编程进阶

    本节内容: 面向对象高级语法部分 经典式 VS 新式类 静态方法,类方法,属性方法 类的特殊方法 反射 异常处理 Socket开发基础 面向对象高级语法部分 经典类 VS 新式类 先看一串代码: cl ...

  10. shiro-5基于url的权限管理

    1.1 搭建环境 1.1.1 数据库 mysql5.1数据库中创建表:用户表.角色表.权限表(实质上是权限和资源的结合 ).用户角色表.角色权限表. 完成权限管理的数据模型创建. 1.1.2 开发环境 ...