str.join(iterable) Return a string which is concatenation the of the strings in the iterable iterable. The separator between elements is the string providing this method. 返回一个以str为间隔,元素是iterable里元素. >>> a=['a','b','c'] >>> a ['a', 'b',…
序言 在看别人的代码时发现一个方法String.join(),因为之前没有见过所以比较好奇. 跟踪源码发现源码很给力,居然有用法示例,以下是源码: /** * Returns a new String composed of copies of the * {@code CharSequence elements} joined together with a copy of * the specified {@code delimiter}. * //这是用法示例 * <blockquote>…
String.Join大大的方便了我们拼接字符串的处理. 1.普通用法:指定元素间的拼接符号 var ids = new List<int>(); for (int i = 0; i < 10; i++) { ids.Add(i); } var inids = string.Join(",", ids); 输出结果:0,1,2,3,4,5,6,7,8,9 2.特殊场景:在元素上添加符号,例如:一个字符串的数组要作为DB脚本的in的条件,需要加单引号,看看我是怎么做的…
List<string> list = new List<string>(); list.Add("I"); list.Add("Love"); list.Add("You"); string kk = string.Empty; kk = string.Join("-", list); Response.Write(kk); //结果 I-Love-You…
Qualys项目中写到将ServerIP以“,”分割后插入数据库并将重复的IP去除后发送到服务器进行Scan,于是我写了下面的一段用来剔除重复IP: //CR#1796870 modify by v-yangwu, remove the IPs which are repeated. string[] arrayIP = ipAll.Split(','); List<string> listIP = new List<string>(); foreach (string ip in…
(41)StringBuilder is NOT the answer for all string concatenation scenarios; String.Join could be 招数41: StringBuilder不适用于所有字符串连接的场景:String.Join可能是 Yes, if you are in a loop and adding to a string, then a StringBuilder *could* be most appropriate. Howe…