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. jenkins pipeline设置

    转:https://mp.weixin.qq.com/s/MwyBsUWUQASGMr_erGfzZA

  2. 学习JAVAWEB第十一天

    今天以及明天做登录案例,复习所学知识.

  3. springboot 使用select的注解,来查询数据库。

    package com.aaa.zxf.mapper; import com.aaa.zxf.model.Book; import org.apache.ibatis.annotations.*; i ...

  4. mysql自连接?

    一.自连接 /* 自己查询自己 把一张表看成是两张表. 表的设计. */ SELECT * from depart; -- 具体的查询方法,查询 name ,并给添加别名. select d1.nam ...

  5. Elasticsearch(2) 数据搜索

    本文介绍如何在Elasticsearch中对数据进行搜索. 1.简述 在Elasticsearch中的搜索中,有两类搜索: queries aggregations 区别在于:query可以进行全文搜 ...

  6. 如何在 VS Code 中为 Java 类生成序列化版本号

    前言 IDEA 提供自动生成序列化版本号的功能,其实 VS Code 也可以,只是默认关闭了这个功能,下面就来看看如何开启这个功能吧. 配置过程 首先需要保证 VS Code 上安装了提供 Java ...

  7. ApacheCN C# 译文集 20211124 更新

    C# 代码整洁指南 零.前言 一.C# 代码标准和原则 二.代码审查--过程和重要性 三.类.对象和数据结构 四.编写整洁的函数 五.异常处理 六.单元测试 七.端到端系统测试 八.线程和并发 九.设 ...

  8. Linux之shell入门

    一.编写规范 代码规范: #!/bin/bash [指定告知系统当前这个脚本要使用的shell解释器] shell相关指令 文件命名规范: 文件名.sh .sh是linux下bash shell 的默 ...

  9. aidl的应用场景

    支付宝 package com.tesy.alipay; import com.test.alipay.Iservice.Stub; import android.app.Service; impor ...

  10. js对于客户端的区分代码

    //区分设备 function judge_decice() { let ua =navigator.userAgent.toLowerCase(); if(/android|adr/gi.test( ...