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. JDK目录介绍

    bin目录:存放Java的编译器.解释器等工具(可执行文件). db目录:JDK7附带的一个轻量级的数据库,名字叫做Derby. include目录:存放的调用系统资源的接口文件. jre目录:存放J ...

  2. 深入分析Java中的关键字static

    在平时开发当中,我们经常会遇见static关键字.这篇文章就把java中static关键字的使用方法的原理进行一个深入的分析.先给出这篇文章的大致脉络: 首先,描述了static关键字去修饰java类 ...

  3. Springcloud-微服务

    1.什么是微服务? 通过阅读马丁弗勒关于描述微服务的文章(https://martinfowler.com/articles/microservices.html),在此特作仅用作个人理解的关于微服务 ...

  4. MSTP多生成树协议

    MSTP多生成树协议 目录 MSTP多生成树协议 1.MSTP(Multiple Spanning Tree Protocol)概述 2.STP.RSTP.PVST的应用缺陷 3.MSTP的主要特点 ...

  5. Arch Linux遇到的坑(下)

    明天就要开学,终于赶忙又熟悉了新环境的用法,现在已经基本满足了日常需求,再记录一些坑-. 电脑没有声音 因为上次离奇的自己好了,我就没有再管了,但是后来使用chrome的时候还是没有声音,我就用了图形 ...

  6. 为hade增加model自动生成功能

    大家好,我是轩脉刃. 我们写业务的时候和db接触是少不了的,那么要生成model也是少不了的,如何自动生成model,想着要给hade框架增加个这样的命令. 看了下网上的几个开源项目,最终聚焦在两个项 ...

  7. weblogic12c安装笔记

    weblogic12c安装笔记 1.创建wls用户 useradd wls 2.切换到wls用户 su - wls 3.在/home/wls/创建files.jdk1.8.patch.bao目录 mk ...

  8. python内置模块之re模块

    内容概要 re模块常用方法 findall search match re模块其他方法 split sub subn compile finditer findall 对无名分组优先展示 re实战之爬 ...

  9. Solution -「多校联训」数学考试

    \(\mathcal{Description}\)   Link.   给定 \(n\) 个函数,第 \(i\) 个有 \(f_i(x)=a_ix^3+b_ix^2+cx_i+d~(x\in[l_i, ...

  10. set和setenv

    今天用set设置PATH变量(加一个路径),发现虽然echo的时候显示修改成功了,实际执行命令的时候确没有去那个路径查找:当前shell是c shell(csh). 在网上找了一些材料,总结如下:   ...