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对象原型的考察.
随机推荐
- 章鱼哥出品—VB.NET DataGridView绑定数据源 "与货币管理器的位置关联的行不能设置为不可见" 问题的解决
DtaGridView绑定数据源后.假设想让数据条件显示的话,直接使用 My_Row.Visible = False就会出错.错误类型是 "与货币管理器的位置关联的行不能设置为不可见&qu ...
- plot sin 04 坐标轴居中
plot sin 04 坐标轴居中 code #!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import matpl ...
- C语言 · 判定字符位置
算法训练 6-3判定字符位置 时间限制:1.0s 内存限制:512.0MB 返回给定字符串s中元音字母的首次出现位置.英语元音字母只有‘a’.‘e’.‘i’.‘o’.‘u’五个. 若 ...
- Jackson2.1.4 序列化格式化时间
public class User { private int id; private Date birthday; private double money; private String name ...
- Java实现 简单聊天软件
简单的聊天软件 //客户端 package yjd9; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ...
- Phalcon的MVC框架解析
1. mvc/simple从最简单的入手吧. 把一些能及时说明白的东西写在注释里了,需要扩展的知识列在下面. public/index.php <?php $loader = new \Phal ...
- Boostrap入门级css样式学习
1. 自适应网页设计 首先,在网页代码的头部,加入一行 viewport元标签.viewport是网页默认的宽度和高度, <meta name="viewport" cont ...
- C++ IO流小结
撒花庆祝下,终于看完了(C++Primer)第一部分,即将进入第二部分! IO部分,最基本的是iostream(istream.ostream),子类有fstream(ifstream.ofstrea ...
- (转)x264参数中文详解(X264 Settings)
0 解释x264命令可选项的用途和使用方法.同执行 x264 --fullhelp 显示顺序.本文主要翻译:mewiki.project357.com/wiki/X264_Settings,同时参考d ...
- (转)V4L2 Video overlay, Video output, Video output overlay的区别
原文地址:http://blog.csdn.net/kickxxx/article/details/7755127 三者都是V4L2定义的接口,英文原文参见 http://v4l2spec.bytes ...