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 ...
随机推荐
- mybtis 基础
一.什么是mybatis MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBati ...
- angular中的服务
angular中的服务 angular中的服务相当于一个状态管理,可以将数据放在服务里面进行获取以及编辑. 服务的安装命令: ng g service count 安装好后,会在服务的ts文件中引入一 ...
- Linux 检查 外部设备 是否存在
以 USB 为例,如果移植了udev,那么在usb插入的时候,/dev下面会出现usb有关的设备,同时,自动挂载到文件系统的某个节点 如果以文件系统usb对应的挂载点来检测USB是否插入,是不够严谨的 ...
- getResource()和getResourceAsStream以及路径问题【转】【补】
一 getResource 用JAVA获取文件,听似简单,但对于很多像我这样的新人来说,还是掌握颇浅,用起来感觉颇深,大常最经常用的,就是用JAVA的File类,如要取得c:/test.txt文件,就 ...
- retry示例
#!/usr/bin/python2.7 # -*- coding: utf-8 -*- import time import exceptions def func(): # a,b = None ...
- Silverlight程序之修改命名空间
有时候,为了使用已有的代码,可能需要更改主程序的命名空间,以生成新的应用.修改命名空间,不能胡乱一通全部使用“替换”,否则程序可能无法正常运行.通过笔者实践,主要有以下几个地方需要注意(以WebGIS ...
- 错误 1 未能找到类型或命名空间名称“DataPager”(是否缺少 using 指令或程序集引用?)
鄙人在设计器SearchTab.xaml中添加了如下一个分页控件: <sdk:DataPager x:Name="dataPagerPrj" Grid.Row="3 ...
- Python之线程 2 - Python实现线程
一 python与线程 1.全局解释器锁GIL(用一下threading模块之后再来看~~) 2.python线程模块的选择 二 Threading模块 1.线程创建 2.多线程与多进程 3.多线程实 ...
- Coursera, Deep Learning 2, Improving Deep Neural Networks: Hyperparameter tuning, Regularization and Optimization - week1, Course
Train/Dev/Test set Bias/Variance Regularization 有下面一些regularization的方法. L2 regularation drop out da ...
- luogu P3767 膜法
传送门 这题如果没有删除操作,可以直接使用可持久化并查集 注意到这种可持久化的依赖关系(是这样说的把)是一棵树,然后对于一个点,自己的操作会影响自己的那棵子树,并且如果是删除操作,就会使得一个子树没有 ...