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 Bootstarp框架和inconfont、font-awesome使用

    http://www.bootcss.com/ http://www.runoob.com/bootstrap/bootstrap-panels.html  查找基本的没问题 https://www. ...

  2. Hadoop记录-Hive调优:让任务并行执行

    set mapred.job.queue.name=pms;   //设置队列set hive.exec.reducers.max=8;  //设置最大的reducersset mapred.redu ...

  3. Jpush极光推送

    require 'jpush' class SidkiqJpushWorker include Sidekiq::Worker # args[0] msg : args[1] region_id ; ...

  4. vue实现商品累计效果

    vue实现商品累计需要以下几点 1.添加商品 2.选中 3.删除功能 4.总计功能 <div id="main"> <div class="con&qu ...

  5. Docker-01 无人值守升级 CentOS 6.x 系统内核到 3.10.x 长期支持版

    #!/bin/bash # # 无人值守升级 CentOS .x 系统内核到 3.10.x 长期支持版 # # # .检查操作系统是否为 CentOS .x # cat /etc/centos-rel ...

  6. Native/Webview bridge for Hybrid

    Native/Webview bridge for Hybrid 安装 npm i --save webview-bridge 特点 支持自定义app URL scheme 支持多种处理方式(全部涵盖 ...

  7. Ubuntu中安装python3.6(转)

    因为TensorFlow只支持到python3.6,所以安装python3.6版本 Python3.6的使用越来越普遍.Ubuntu16.04的版本中默认胸自带python2和python3.5的版本 ...

  8. Java EE之Hibernate异常总结org.hibernate.MappingException: Repeated column in mapping for entity:

    解决方案/原因: 一个pojo(JavaBean)中不能有两个属性同时映射到一个数据库字段上 即使是一个属性的两个getter方法也不行 %%%% Error Creating SessionFact ...

  9. 第25月第18天 vue

    1.cnpm sudo chown -R $USER /usr/local  npm install -g cnpm --registry=https://registry.npm.taobao.or ...

  10. Expression知识

    http://www.cnblogs.com/Ninputer/archive/2009/08/28/expression_tree1.html#!comments