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. cocos2dx坐标系介绍

    GL坐标系 Cocos2D以OpenglES为图形库,所以它使用OpenglES坐标系.GL坐标系原点在屏幕左下角.x轴向右.y轴向上. 屏幕坐标系 苹果的Quarze2D使用的是不同的坐标系统,原点 ...

  2. 解决 Plugin with id 'com.github.dcendents.android-maven' not found.

    在Android studio中引用第三方库的时候,报这个错. Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not ...

  3. 【Unity/C#】DateTime时间字符串,月份用英文显示

    制作一个钟表,要求效果如下图: 由于每一部分的字体大小不同,我分别使用了不同的Text控件.(不懂dalao们有没有更科学的办法) 把这些Text控件包含在一个Object下,给该Object定义一个 ...

  4. 各种不同的mq

    目前业界有很多MQ产品,我们作如下对比: RabbitMQ 是使用Erlang编写的一个开源的消息队列,本身支持很多的协议:AMQP,XMPP, SMTP, STOMP,也正是如此,使的它变的非常重量 ...

  5. 可变参数宏...和__VA_ARGS__

    __VA_ARGS__ 是一个可变参数的宏,很少人知道这个宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持).实现思想就是宏定义中参数列表的最后一个参数为 ...

  6. jar/war/ear文件的区别

     jar/war/ear三种文件,在文件结构上,三者并没有什么不同,它们都采用zip或jar档案文件压缩格式.但是它们的使用目的有所区别: Jar文件(扩展名为. Jar)包含Java类的普通库.资源 ...

  7. Windoows窗口程序五

    程序执行机制 过程驱动-程序的执行过程是按照预订好的顺序执行. 事件驱动-程序的执行是无序,用户可以根据需要随机触发相应的事件. Win32窗口程序就是采用事件驱动方式执行,也就是消息机制. 当系统通 ...

  8. imx6 android power off

    调试android4.2的关机功能,希望再按下power按键长时间之后就关机.不弹出选框. 参考链接 http://www.cnblogs.com/sardine/archive/2011/07/26 ...

  9. python不同package下相互调用

    路径如: /path/dir1/a.py /path/dir2/b.py 调用举例如: 在/path/dir2/b.py中调用 a模块 import sys sys.path.append(" ...

  10. PHP curl_setopt函数用法介绍补充篇

    1.curl数据采集系列之单页面采集函数get_html 单页面采集在数据采集过程中是最常用的一个功能 有时在服务器访问限制的情况下 只能使用这种采集方式 慢 但是可以简单的控制 所以写好一个常用的c ...