雷火电竞-中国电竞赛事及体育赛事平台

歡迎來(lái)到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

C# 字符串、數(shù)組和List的截取和轉(zhuǎn)換實(shí)例

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊:

如下所示:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
 
namespace ConsoleApp1
{
  class Program
  {
    /// <summary>
    /// 字符串,數(shù)組和List的截取,轉(zhuǎn)換
    /// </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();//小寫字母轉(zhuǎn)換成大寫字母--ABCDEFGHIJ1234567890
      string str10 = str0.ToLower();//大寫字母轉(zhuǎn)換成小寫字母--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);//截取從開始字符串到結(jié)束字符串范圍--cdefghij123
      string s = "a,b,c,d,e,f,g,h,i,j";
      string[] strArray = s.Split(','); //字符串轉(zhuǎn)數(shù)組
      string str13 = string.Join(",", strArray);//數(shù)組轉(zhuǎn)字符串
      List<string> list = new List<string>(s.Split(','));//字符串轉(zhuǎn)List
      string str14 = string.Join(",", list.ToArray());//List轉(zhuǎn)字符串
      string[] str15 = list.ToArray();//List轉(zhuǎn)數(shù)組
      List<string> listS = new List<string>(str15);//數(shù)組轉(zhuǎn)List
      Console.WriteLine(str0);
      Console.WriteLine(str12);
      Console.ReadLine();
    }
  }
   
}

以上這篇C# 字符串、數(shù)組和List的截取和轉(zhuǎn)換實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持我們。

上一篇:C#提取PPT文本和圖片的實(shí)現(xiàn)方法

欄    目:C#教程

下一篇:C#連接Oracle數(shù)據(jù)庫(kù)使用Oracle.ManagedDataAccess.dll

本文標(biāo)題:C# 字符串、數(shù)組和List的截取和轉(zhuǎn)換實(shí)例

本文地址:http://www.jygsgssxh.com/a1/C_jiaocheng/5413.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有