标签:
https://msdn.microsoft.com/zh-cn/library/tk0xe5h0
官方样例
串联字符串数组的指定元素,其中在每个元素之间使用指定的分隔符。
命名空间: System
程序集:
mscorlib(mscorlib.dll 中)
public static string Join(
string separator,
string[] value,
int startIndex,
int count
)
// Sample for String.Join(String, String[], int int) using System; class Sample { public static void Main() { String[] val = {"apple", "orange", "grape", "pear"}; String sep = ", "; String result; Console.WriteLine("sep = ‘{0}‘", sep); Console.WriteLine("val[] = {{‘{0}‘ ‘{1}‘ ‘{2}‘ ‘{3}‘}}", val[0], val[1], val[2], val[3]); result = String.Join(sep, val, 1, 2); Console.WriteLine("String.Join(sep, val, 1, 2) = ‘{0}‘", result); } } /* This example produces the following results: sep = ‘, ‘ val[] = {‘apple‘ ‘orange‘ ‘grape‘ ‘pear‘} String.Join(sep, val, 1, 2) = ‘orange, grape‘ */
Console.WriteLine("************************************************************"); List<string> names = new List<string> { "李意义1", "李意义2", "李礼物1", "李礼物2", "单罗1", "单罗2", "单1", "单2", "单", "1", "2", "罗", "Yuri" }; //目标状态:{李***,李***,李***,单**,单**,单*,单*,单,1,2,罗,Y***}; string[] find = { "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*" }; for (int i = 0; i < names.Count; i++) { string temp = names[i][0] + string.Join("", find, 0, names[i].Length-1); Console.WriteLine(temp); } List<string> phone = new List<string> { "152", "15347834899", "1", "8967382" }; for (int i = 0; i < phone.Count; i++) { if (phone[i].Length>7) { string temp = phone[i].Substring(0, 3) + "****" + phone[i].Substring(7); Console.WriteLine(temp); } else if (phone[i].Length>3) { string temp = phone[i].Substring(0, 3) +string.Join("",find,0, phone[i].Length-3); Console.WriteLine(temp); } else { Console.WriteLine(phone[i]); } } Console.ReadKey();
String.Join重载String.Join 方法 (String, String[], Int32, Int32)
标签:
原文地址:http://www.cnblogs.com/danlis/p/5347437.html