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. AI换脸实战教学(FaceSwap的使用)---------第一步Extration:提取人脸。

    市面上有多款AI换脸的方法,笔者这里节选了Github那年很火的开源项目FaceSwap: (很早就实践了,但是忘记记录啦hhh,请勿用于不正当用途哦) 做了一篇详细教学,包括配置,参数设置,换脸效果 ...

  2. Spring系列9:基于注解的Spring容器配置

    写在前面 前面几篇中我们说过,Spring容器支持3种方式进行bean定义信息的配置,现在具体说明下: XML:bean的定义和依赖都在xml文件中配置,比较繁杂. Annotation-based ...

  3. 同态加密与 Paillier/RSA

    本文作者: wdxtub 本文链接: http://wdxtub.com/flt/flt-03/2020/12/02/ 白话同态加密 虽然同态加密即使现在听起来也很陌生,但是其实这个概念来自 1978 ...

  4. 1. idea spark scala 语言支持设置

     Spark 版本为 3.0.0,默认采用的 Scala 编译版本为 2.12 1. 创建名为spark-project 的项目  2. 将src 删除,把spark-project 当成一个父项目, ...

  5. uni微信小程序优化,几行代码就能省100kb的主包空间?

    不是标题党,我们公司的项目确确实实是省下了100kb的主包空间,而且还是在没有牺牲任何的性能和业务的前提下实现的. 但是100kb是根据项目大小,所以你用这个插件可能省下超过100kb或者更少. 直接 ...

  6. java中使用反射获取pojo(实体)类的所有字段值

    出处:https://developer.aliyun.com/article/239346 说起反射,不得不说它实在是太强大了,通过反射就可以轻轻松松拿到各种东东,如果你想在项目中解除对某个类的依赖 ...

  7. 使用@WebServlet等注解需要i注意的

    Servlet 3.0 的部署描述文件 web.xml 的顶层标签 <web-app> 有一个 metadata-complete 属性,该属性指定当前的部署描述文件是否是完全的.如果设置 ...

  8. Android中四大组件

    Activity  BroadCast Receiver 广播接收者 Service  服务 Content Provider 内容提供者   四大组件都需要在清单文件里面配置一下

  9. cross-env 作用

    是什么 运行跨平台设置和使用环境变量的脚本 出现原因 当您使用NODE_ENV =production, 来设置环境变量时,大多数Windows命令提示将会阻塞(报错). (异常是Windows上的B ...

  10. Python property动态属性

    from datetime import datetime, date class User: def __init__(self, name, birthday): self.name = name ...