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. python网络爬虫-数据储存(七)

    数据储存 主要介绍两种数据储存方法: 储存在文件中,包括text文件和csv文件 存储在数据库中,包括MySQL关系型数据库和mongoDB数据库 存储到txt title = "第一个文本 ...

  2. Android系统编程入门系列之硬件交互——通信硬件Bluetooth

    通信硬件NFC的文章,虽然可以在Android系统中通过非直接接触的形式与支持NFC硬件的设备通信,但是也只能交互一些简短的标签内容,对大量的持续性数据,却并不能很好的支持.因此针对这个弊端,可以考虑 ...

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

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

  4. 如何美化 Matplotlib 3D坐标系

    前言 ~mpl_toolkits.mplot3d 生成的3D坐标系背景色是灰色的,刻度线也向内延伸了,如果搭配上其他白色背景的 2D 图,看起来很奇怪,比如下面这张图: 网上有一些办法可以将3D坐标区 ...

  5. Android 动态申请权限问题【转】

    Android 动态申请权限问题 感谢大佬:https://www.jianshu.com/p/2324a2bdb3d4 感谢大佬:https://blog.csdn.net/weixin_42910 ...

  6. 使用 Element UI Select 组件的 value-key 属性,让绑定值可以为一个对象

    EsunR 2019-11-07 12:14:42  12264  收藏 6 分类专栏: Vue 文章标签: element-ui 版权 当我们使用 Elemet UI 的选择组件进行多选时,Sele ...

  7. NSTimer的使用

    开启定时器 @property (nonatomic, weak) NSTimer *timer; // 返回一个自动开始执行任务的定时器 self.timer = [NSTimer schedule ...

  8. Linux小技巧scp命令

    Linux服务器运维小技巧scp命令详细教程. 前言 今天给大家带来的是linux中比较实用的命令scp.善用小技巧,解决工作中的痛点. 掌握一门好的技术或者说一门好的艺术,最快捷的方式就是融入到工作 ...

  9. Java读写文件常用方法

    一.字符流:读写纯文本(txt,csv等), 1 字符流写文件主要用:FileWriter,BufferedWriter,PrintWriter 1.1 测试 FileWriter 写入 privat ...

  10. Python内置模块(re+collections+time等模块)

    Python内置模块(re+collections+time等模块) 1. re模块 import re 在python要想使用正则必须借助于模块 re就是其中之一 1.1 findall功能( re ...