String.Join重载String.Join 方法 (String, String[], Int32, Int32)
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)的更多相关文章
- android将String转化为MD5的方法+一些String经常使用的方法
public class StringUtils { public static String MD5Encode(String origin) { String resultString = nul ...
- Android中 int 和 String 互相转换的多种方法
1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...
- android 中int 和 String 互相转换的多种方法
1 .如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt( ...
- java中将string类型转int类型或者将string类型转long类型方法
将字串 String 转换成整数 int 两种方法: 1).int i = Integer.parseInt("111"); 或 i = Integer.parseInt([Str ...
- java中的BigDecimal和String的相互转换,int和String的类型转换,Integer类和String相互转换
一: /*由数字字符串构造BigDecimal的方法 *设置BigDecimal的小数位数的方法 */ 注:BigDecimal在数据库中存的是number类型. import java.math.B ...
- Javascript String类的属性及方法
String 类 Attribute and method anchor() 创建一个<a>标签的实例,将其name属性设置为被传递给此方法的字符串 big() ...
- js中关于string的一些常用的方法
最近总结了一些关于string中的常用方法, 其中大部分的方法来自于<JavaScript框架设计>这本书, 如果有更好的方法,或者有关于string的别的常用的方法,希望大家不吝赐教. ...
- JS删除String里某个字符的方法
关于JS删除String里的字符的方法,一般使用replace()方法.但是这个方法只会删除一次,如果需要将string里的所以字符都删除就要用到正则. 1 2 3 4 var str = " ...
- 一道前端面试题:定义一个方法将string的每个字符串间加个空格返回,调用的方式'hello world'.spacify();
偶然在群里看到了这道题:定义一个方法将string的每个字符串间加个空格返回,调用的方式'hello world'.spacify(); 这道题主要是对JavaScript对象原型的考察.
随机推荐
- 【高可用HA】Apache (3) —— Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy
Mac下配置Apache Httpd负载均衡(Load Balancer)之mod_proxy httpd版本: httpd-2.4.17 参考来源: Apache (1) -- Mac下安装Apac ...
- Web API(一);Restful架构
一.什么是RESTful REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移.REST指的是一组架构约束条件和原则.如果一个 ...
- B2B(企业对企业)、B2C(企业对个人)、C2C(个人对个人)
B2B(企业对企业).B2C(企业对个人).C2C(个人对个人)
- php插入htm htm插入php的变量
<?php $file = "ueditor\php\upload\image\*\*.png"; foreach (glob("$file") as $ ...
- 【转】【VC】VC程序运行时间测试函数
1:Sleep函数 使用: sleep(1000),在Windows和Linux下1000代表的含义并不相同,Windows下的表示1000毫秒,也就是1秒钟: Linux下表示1000秒,Linux ...
- nodejs基础 -- 回调函数
Node.js 异步编程的直接体现就是回调. 异步编程依托于回调来实现,但不能说使用了回调后程序就异步化了. 回调函数在完成任务后就会被调用,Node 使用了大量的回调函数,Node 所有 API 都 ...
- C++中成员变量默认private
struct 默认是 publicclass 默认是 private
- 使用Ultra Librarian转换芯片的Altium Designer封装格式
第一步:找到对应芯片的CAD文件,以OPA350为例: http://www.ti.com/product/opa350 RE: 使用Ultra Librarian转换TI芯片的Altium De ...
- rdesktop连接远程windows
$ info rdesktop //看一下帮助信息吧$rdesktop 192.168.1.1 //打开了一个8位色彩的,$rdesktop -a 16 192.168.1.1 //这个是16位色 ...
- PHP 5种方式获取文件后缀名
<?php header("content-type:text/html;charset=utf-8"); function get_ext1($filename) { re ...