using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading; namespace ConsoleApp1
{
class Program
{
/// <summary>
/// 字符串,数组和List的截取,转换
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
string str = "abcdefghij1234567890";
int i = 4;
string str1 = str.Substring(0, i);//截取字符串前i位--abcd
string str2 = str.Remove(i, str.Length - i);//移除字符串i位后面的字符=截取字符串前i位--abcd
string str3 = str.Remove(0, i);//截取字符串i位之后的字符串--efghij1234567890
string str4 = str.Substring(i);//截取字符串i位之后的字符串--efghij1234567890
string str5 = str.Substring(str.Length - i);//截取字符串后i位--7890
string str6 = str.Remove(0, str.Length - i);//截取字符串后i位--7890
string str7 = str.Substring(0, str.Length - i);//去掉字符串后i位--abcdefghij123456
string str8 = str.Remove(str.Length - i, i);//去掉字符串后i位--abcdefghij123456
string str9 = str.Replace("abc", "ABC");//替换字符串中的字符串--ABCdefghij1234567890
string str0 = str.ToUpper();//小写字母转换成大写字母--ABCDEFGHIJ1234567890
string str10 = str0.ToLower();//大写字母转换成小写字母--abcdefghij1234567890
string str11= str.Substring(str.Length - 1, 1);//截取字符串最后一位--0
int m = str.IndexOf("cde") + 1;
int n = str.IndexOf("23");
string str12 = str.Substring(m, n - m + 2);//截取从开始字符串到结束字符串范围--cdefghij123
string s = "a,b,c,d,e,f,g,h,i,j";
string[] strArray = s.Split(','); //字符串转数组
string str13 = string.Join(",", strArray);//数组转字符串
List<string> list = new List<string>(s.Split(','));//字符串转List
string str14 = string.Join(",", list.ToArray());//List转字符串
string[] str15 = list.ToArray();//List转数组
List<string> listS = new List<string>(str15);//数组转List
var intersectedList = list.Intersect(listS);//两个List交集
var expectedList = list.Except(listS);//两个List取差
var mergedList = list.Merge(listS);//两个List取联集
var result = list.Union(listS).ToList<int>(); //除去重复
var result1 = list.Concat(listS).ToList<int>();//保留重复
var result2 = list.BinarySearch("1");//判断集合中是否包含某个值.如果包含则返回0
Console.WriteLine(str0);
Console.WriteLine(str12);
Console.ReadLine();
}
} }

C# 字符串、数组和List的截取和转换的更多相关文章

  1. 复杂的字符串数组解析:{"setting":"简单:10:5,一般:5:10,困难:2:20"},使用split多次截取

    "[0,{"id":563,"name":"测试题1","dscr":null,"picId&quo ...

  2. java根据输入的字符串和字节数来截取,输出对应字节数的字符串

    public class Test { //要进行截取操作的字符串 static String ss; //截取的字符串的字节数 static int n; public static void ma ...

  3. Python web前端 08 字符串 数组 json

    Python web前端 08 字符串 数组 json 一.string #string 字符串 #索引 下标 偏移量 ---从0开始 str[index]; #通过索引取字符串 可读不可写 str. ...

  4. JS 常用字符串,数组操作

    JavaScript String/Array对象 JS String对象   String 对象属性 属性 描述 constructor 对创建该对象的函数的引用 length 字符串的长度 pro ...

  5. java求字符串数组交集、并集和差集

    import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Ma ...

  6. Javascript-常用字符串数组操作

    字符串的操作在编写Js的过程中是不可避免的 因为它太多的API 还有相似的API让我们很头痛 为了避免以后遇到模拟两可的问题 还是做个笔记比较好 把常用的字符串操作记录下来成笔记 方便以后查找 No1 ...

  7. Matlab 之 字符串数组查找

    Matlab的优势在于向量操作,字符串操作往往费时费力,但是如果能充分利用Matlab自带的一些函数,也可以取得不错的效果.下面就介绍一下字符串数组查找的小技巧. 字符串数组我通常会选择应用cell格 ...

  8. 探讨js字符串数组拼接的性能问题

    这篇文章主要介绍了有关js对字符串数组进行拼接的性能问题,字符串连接一直是js中性能最低的操作之一,应该如何解决呢?请参看本文的介绍 我们知道,在js中,字符串连接是性能最低的操作之一. 例如: 复制 ...

  9. C语言学习018:strdup复制字符串数组

    在C语言学习005:不能修改的字符串中我们知道字符串是存储在常量区域的,将它赋值给数组实际是将常量区的字符串副本拷贝到栈内存中,如果将这个数组赋值给指针,我们可以改变数组中的元素,就像下面那样 int ...

随机推荐

  1. Linux 学习2

    1.配置好阿里云yum源生成yum缓存下载nginx,并且启动nginx服务,使用浏览器访问,nginx页面 yum源的工作目录是? https://www.cnblogs.com/dlh-lmsh/ ...

  2. 3,linux-yum源配置-systemctl服务管理-文件权限

    3,linux-yum源配置-systemctl服务管理-文件权限 小问答: 1.配置好阿里云yum源 生成yum缓存 下载nginx,并且启动nginx服务,使用浏览器访问10.0.0.10:80 ...

  3. java命令- (学习)jps

    jps(Java Virtual Machine Process Status Tool) 是java提供的一个显示当前所有java进程pid的命令,适合在linux/unix平台上简单察看当前jav ...

  4. json解析出现:java.lang.ClassCastException: net.sf.ezmorph.bean.MorphDynaBean cannot be cast to XXX

    感谢大佬:https://blog.csdn.net/one_ink/article/details/99817676 一.出错原因 当我们利用json解析中的toBean方法时,如果它的属性里面包含 ...

  5. node.js中的fs.appendFile方法使用说明

    方法说明: 该方法以异步的方式将 data 插入到文件里,如果文件不存在会自动创建.data可以是任意字符串或者缓存. 语法: 代码如下: fs.appendFile(filename, data, ...

  6. iOS WKWebView 使用笔记

    首先添加Webkit框架

  7. ◆JAVA加密解密-DES

    DES算法提供CBC, OFB, CFB, ECB四种模式,MAC是基于ECB实现的. 一.数据补位 DES数据加解密就是将数据按照8个字节一段进行DES加密或解密得到一段8个字节的密文或者明文,最后 ...

  8. 北京太速科技-第六代Intel i7四核八线程6U VPX主控板

    一.产品概述 该产品是一款基于第六代Intel i7四核八线程的高性能6U VPX刀片式计算机.产品提供了可支持全网状交换的高速数据通道,其中P1,P2各支持4个PCIe x4 Gen3总线接口,P3 ...

  9. NPM 错误、问题等汇总

    一. npm的作用就是对Node.js依赖的包进行管理,也可以理解为用来安装/卸载Node.js需要装的东西 二. 1. 修改npm配置为淘宝的源下载: npm install -g cnpm --r ...

  10. 主机磁盘使用率超过85%导致es索引变为只读模式

    [ type=cluster_block_exception, reason=index [ index_name ] FORBIDDEN/12/index read-only / allow del ...