C# 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的更多相关文章
- BCL中String.Join的实现
在开发中,有时候会遇到需要把一个List对象中的某个字段用一个分隔符拼成一个字符串的情况.比如在SQL语句的in条件中,我们通常需要把List<int>这样的对象转换为“1,2,3”这样的 ...
- c# String.Join 和 Distinct 方法 去除字符串中重复字符
1.在写程序中经常操作字符串,需要去重,以前我的用方式利用List集合和 contains去重复数据代码如下: string test="123,123,32,125,68,9565,432 ...
- String.Join的巧用
String.Join大大的方便了我们拼接字符串的处理. 1.普通用法:指定元素间的拼接符号 var ids = new List<int>(); for (int i = 0; i &l ...
- string.Join()的用法
List<string> list = new List<string>(); list.Add("I"); list.Add("Love&quo ...
- string.join加引号
columnsGen = string.Join(",", modelDictionary.Keys); valueGen = modelDictionary.Values.Agg ...
- String.Join 和 Distinct 方法 去除字符串中重复字符
Qualys项目中写到将ServerIP以“,”分割后插入数据库并将重复的IP去除后发送到服务器进行Scan,于是我写了下面的一段用来剔除重复IP: //CR#1796870 modify by v- ...
- String.join()方法的使用
String.join()方法是JDK1.8之后新增的一个静态方法,使用方式如下所示: String result = String.join("-","java&qu ...
- 教你50招提升ASP.NET性能(二十三):StringBuilder不适用于所有字符串连接的场景;String.Join可能是
(41)StringBuilder is NOT the answer for all string concatenation scenarios; String.Join could be 招数4 ...
- Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5
linq to sql 的时候,有时候需要用到 先group 然后来个 aggregate 串连一下值, 但会总会出错,说不识别 aggregate 或者 string.join 方法 搜遍网络 一 ...
- string.Join和string.Concat的区别
源自Difference between String.Join() vs String.Concat() With .NET 4.0, String.Join() uses StringBuilde ...
随机推荐
- 阿里云申请ssl证书配置tomcat访问https
首先去阿里云上面申请ssl证书,免费的,自己百度去. 申请完ok之后会让你下载一个压缩包,里面有四个文件. 在tomcat安装目录下创建cert文件夹,把这四个文件扔进去 在conf/server.x ...
- mysql 常用的命令集合
1.创建表 CREATE TABLE `cardPcitrue`( `id` INT AUTO_INCREMENT NOT NULL PRIMARY KEY COMMENT'编号', `cId` IN ...
- Vue项目搭建
1.环境搭建 安装node 官网下载安装包,傻瓜式安装:https://nodejs.org/zh-cn/ 安装cnpm npm install -g cnpm --registry=https:// ...
- 谈一谈Elasticsearch的集群部署
Elasticsearch天生就支持分布式部署,通过集群部署可以提高系统的可用性.本文重点谈一谈Elasticsearch的集群节点相关问题,搞清楚这些是进行Elasticsearch集群部署和拓 ...
- HDU 1039(字符串判断 **)
题意是检查一个字符串是否满足三个条件: 一.至少有一个元音字母.二.不能出现三个连续的元音或三个连续的辅音.三.除了 ee 和 oo 外不能出现两个连续相同字母. 若三个条件都能满足,该字符串满足条件 ...
- python3.x与2.x区别
1.性能 Py3.0运行 pystone benchmark的速度比Py2.5慢30%.Guido认为Py3.0有极大的优化空间,在字符串和整形操作上可 以取得很好的优化结果. Py3.1性能比Py2 ...
- ASP.NET MVC动态加载数据
ASP.NET MVC动态加载数据,一般的做法是使用$.each方法来循环产生tabel: 你可以在html时先写下非动态的部分: Source Code 上图中,有一行代码: <tbody ...
- String,StringBuilder,StringBuffer区别
一.String,StringBuilder,StringBuffer的大概了解 大家知道String,StringBuilder,StringBuffer三个的基本应用场景. String会一直创建 ...
- Spark Streaming连接Kafka的两种方式 direct 跟receiver 方式接收数据的区别
Receiver是使用Kafka的高层次Consumer API来实现的. Receiver从Kafka中获取的数据都是存储在Spark Executor的内存中的,然后Spark Streaming ...
- python之import模块及包的调用
模块概念 在Python中,一个.py文件就称之为一个模块(Module).使用模块组织代码,最大的好处是大大提高了代码的可维护性 模块一共三种:python标准库.第三方模块.应用程序自定义模块. ...