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…
源自Difference between String.Join() vs String.Concat() With .NET 4.0, String.Join() uses StringBuilder class internally so it is more efficient.Whereas String.Concat() uses basic concatenation of String using "+" which is of course not an efficie…