https://msdn.microsoft.com/zh-cn/library/tk0xe5h0

String.Join 方法 (String, String[], Int32, Int32)

官方样例

串联字符串数组的指定元素,其中在每个元素之间使用指定的分隔符。

命名空间:   System
程序集:
 mscorlib(mscorlib.dll 中)

public static string Join(
string separator,
string[] value,
int startIndex,
int count
)
        // 摘要:
        //     串联字符串数组的指定元素,其中在每个元素之间使用指定的分隔符。
        //
        // 参数:
        //   separator:
        //     要用作分隔符的字符串。
        //
        //   value:
        //     一个数组,其中包含要连接的元素。
        //
        //   startIndex:
        //     value 中要使用的第一个元素。
        //
        //   count:
        //     要使用的 value 的元素数。
        //
        // 返回结果:
        //     由 value 中的字符串组成的字符串,这些字符串以 separator 字符串分隔。- 或 -如果 count 为零,value 没有元素,或
        //     separator 以及 value 的全部元素均为 System.String.Empty,则为 System.String.Empty。
        //
        // 异常:
        //   System.ArgumentNullException:
        //     value 为 null。
        //
        //   System.ArgumentOutOfRangeException:
        //     startIndex 或 count 小于 0。- 或 -startIndex 加上 count 大于 value 中的元素数。
        //
        //   System.OutOfMemoryException:
        //     内存不足。
// 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[], val[], val[], val[]);
result = String.Join(sep, val, , );
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'
*/

Demo

Console.WriteLine("************************************************************");

        List<string> names = new List<string> { "李意义1", "李意义2", "李礼物1", "李礼物2", "单罗1", "单罗2", "单1", "单2", "单", "", "", "罗", "Yuri" };
//目标状态:{李***,李***,李***,单**,单**,单*,单*,单,1,2,罗,Y***};
string[] find = { "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*" };
for (int i = ; i < names.Count; i++)
{
string temp = names[i][] + string.Join("", find, , names[i].Length-);
Console.WriteLine(temp);
} List<string> phone = new List<string> { "", "", "", "" }; for (int i = ; i < phone.Count; i++)
{
if (phone[i].Length>)
{
string temp = phone[i].Substring(, ) + "****" + phone[i].Substring();
Console.WriteLine(temp);
}
else if (phone[i].Length>)
{
string temp = phone[i].Substring(, ) +string.Join("",find,, phone[i].Length-);
Console.WriteLine(temp);
}
else
{
Console.WriteLine(phone[i]);
}
} Console.ReadKey();

测试

String.Join重载String.Join 方法 (String, String[], Int32, Int32)的更多相关文章

  1. android将String转化为MD5的方法+一些String经常使用的方法

    public class StringUtils { public static String MD5Encode(String origin) { String resultString = nul ...

  2. Android中 int 和 String 互相转换的多种方法

    1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

  3. android 中int 和 String 互相转换的多种方法

    1 .如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt( ...

  4. java中将string类型转int类型或者将string类型转long类型方法

    将字串 String 转换成整数 int 两种方法: 1).int i = Integer.parseInt("111"); 或 i = Integer.parseInt([Str ...

  5. java中的BigDecimal和String的相互转换,int和String的类型转换,Integer类和String相互转换

    一: /*由数字字符串构造BigDecimal的方法 *设置BigDecimal的小数位数的方法 */ 注:BigDecimal在数据库中存的是number类型. import java.math.B ...

  6. Javascript String类的属性及方法

    String 类 Attribute and method anchor()              创建一个<a>标签的实例,将其name属性设置为被传递给此方法的字符串 big()  ...

  7. js中关于string的一些常用的方法

    最近总结了一些关于string中的常用方法, 其中大部分的方法来自于<JavaScript框架设计>这本书, 如果有更好的方法,或者有关于string的别的常用的方法,希望大家不吝赐教. ...

  8. JS删除String里某个字符的方法

    关于JS删除String里的字符的方法,一般使用replace()方法.但是这个方法只会删除一次,如果需要将string里的所以字符都删除就要用到正则. 1 2 3 4 var str = " ...

  9. 一道前端面试题:定义一个方法将string的每个字符串间加个空格返回,调用的方式'hello world'.spacify();

    偶然在群里看到了这道题:定义一个方法将string的每个字符串间加个空格返回,调用的方式'hello world'.spacify(); 这道题主要是对JavaScript对象原型的考察.

随机推荐

  1. 【Visual Studio】控制台程序运行时一闪而过

    问题:写一个C#控制台程序,运行时控制台一闪而过.程序结束.无法看清控制台输出的结果. 办法: 方法一二三都有人写过百度经验了:怎么解决VS运行程序一闪而过 其实还有一种办法,就是把控制台程序改为Wi ...

  2. [mmc]设备树节点含义

    &mmc3 { status = "okay"; dmas = <&edma &edma >; dma-names = "tx&quo ...

  3. Android--List与ArrayList区别(转)

    转载自:http://www.cnblogs.com/aisiteru/articles/1151874.html List是一个接口,而ArrayList是一个类. ArrayList继承并实现了L ...

  4. C/C++捕获段错误,打印出错的具体位置(精确到哪一行)_转

    转自:C/C++捕获段错误,打印出错的具体位置(精确到哪一行) 修订:2013-02-16 其实还可以使用 glibc 的 backtrace_symbols 函数,把栈帧各返回地址里面的数字地址翻译 ...

  5. win7控制面板一打开就停止的解决方法

    现象:win7系统,打开控制面板后,弹出提示窗口:资源管理器停止工作,需要重启.点重启后,系统自动重建桌面进程.控制面板根本无法使用. 下面是网上找到的方法,如果都不行再参照后面我的解决方法. 1. ...

  6. 【转】C# Async/Await 异步编程中的最佳做法

    Async/Await 异步编程中的最佳做法 Stephen Cleary 近日来,涌现了许多关于 Microsoft .NET Framework 4.5 中新增了对 async 和 await 支 ...

  7. android boot.img unpack pack

    每次编译boot.img都要花比较长的时间,有时候只是更改其中的配置文件. 如果能够将boot.img解压,更改之后再打包的话,就能节省时间. boot.img tools是别人写好的工具,能很好的解 ...

  8. Spring 4 官方文档学习(十)数据访问之OXM

    http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html Java Object 与 XML ...

  9. windows 开启端口

    场景: 解决方法: 选中入站规则,右键选择新建入站规则: 然后 选择“允许连接”,点“下一步”. 效果: 连接成功.

  10. C++測量一段代码的执行时时间

    在电脑里发现的一段C++代码,尽管自己不做C++开发了.还是贴出来,给须要的人 LARGE_INTEGER BegainTime ; LARGE_INTEGER EndTime ; LARGE_INT ...