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 ...
随机推荐
- Hadoop序列化-流量汇总案例
Hadoop序列化案例-流量汇总需求 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Hadoop序列化 1>.为什么要序列化 一般来说,“活的”对象只生存在内存里,关机断 ...
- Hadoop基础-MapReduce入门篇之编写简单的Wordcount测试代码
Hadoop基础-MapReduce入门篇之编写简单的Wordcount测试代码 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本文主要是记录一写我在学习MapReduce时的一些 ...
- Mark标记功能的实现(像手工标记的一样)
今天看到一个网站的标记功能,觉得很不错,先记录一下,emm <!DOCTYPE html> <html lang="en"> <head> &l ...
- uva11916 Emoogle Grid (BSGS)
https://uva.onlinejudge.org/external/119/p11916.pdf 令m表示不能染色的格子的最大行号 设>m行时可以染k种颜色的格子数有ck个,恰好有m行时可 ...
- 【转载】C# 字符串截取
https://blog.csdn.net/maba007/article/details/78424760
- luogu 3045 优先队列反悔/bzoj 2590
N头奶牛,价格Pi,K张优惠券,优惠券购买降为Ci,不超过M的钱最多可买多少奶牛 先将c值k小的加入,将它们省下的钱加入优先队列(省下的钱由少到多),在将k+1-n用p排序,再逐个与优先队列中弹出的比 ...
- ES5新增内容
一.数组API实际开发中forEach和map会多一些=>是es6语法中的arrow function举例:(x) => x + 6相当于function(x){return x + 6; ...
- 第28月第4天 __bridge_transfer
1. /* NSObject.h Copyright (c) 1994-2018, Apple Inc. All rights reserved. */ #if __has_feature(objc_ ...
- AbstractQueuedSynchronizer源码解析
1.简介 AbstractQueuedSynchronizer队列同步器,用来实现锁或者其他同步组件的基础框架 AbstractQueuedSynchronizer使用int类型的volatile变量 ...
- Django REST framework 第三章 CBV
从介绍Django快开始,我们就一直在使用FBV的方式来撰写代码,二者本质上并没有太大的区别,然而到了REST framework,更会倾向于用CBV来写API的视图,后面会看到这个方式的强大,它允许 ...