C # truncation and conversion of strings, arrays, and lists,

Source: Internet
Author: User

C # truncation and conversion of strings, arrays, and lists,

Using System; using System. collections. generic; using System. diagnostics; using System. linq; using System. text; using System. threading; namespace ConsoleApp1 {class Program {/// <summary> /// string, array and List truncation, convert /// </summary> /// <param name = "args"> </param> static void Main (string [] args) {string str = "abcdefghij1234567890 "; int I = 4; string str1 = str. substring (0, I); // capture the first I bit of the string -- abcd string str2 = str. remove (I, str. length-I); // remove the character after the string I-bit = intercept the first I-bit of the string -- abcd string str3 = str. remove (0, I); // capture the string after the I-bit -- efghij1234567890 string str4 = str. substring (I); // capture the string after I-bit -- efghij1234567890 string str5 = str. substring (str. length-I); // The I-bit after the string is intercepted -- 7890 string str6 = str. remove (0, str. length-I); // The I-bit after the string is intercepted -- 7890 string str7 = str. substring (0, str. length-I); // remove the I-bit after the string -- abcdefghij123456 string str8 = str. remove (str. length-I, I); // after removing the string, I-bit -- abcdefghij123456 string str9 = str. replace ("abc", "ABC"); // Replace the string-ABCdefghij1234567890 string str0 = str. toUpper (); // converts lowercase letters to uppercase letters -- ABCDEFGHIJ1234567890 string str10 = str0.ToLower (); // converts uppercase letters to lowercase letters -- abcdefghij1234567890 string str11 = str. substring (str. length-1, 1); // capture the last digit of the string -- 0 int m = str. indexOf ("cde") + 1; int n = str. indexOf ("23"); string str12 = str. substring (m, n-m + 2); // intercept the range from the start string to the end string -- cdefghij123 string s = "a, B, c, d, e, f, g, h, I, j "; string [] strArray = s. split (','); // string to array string str13 = string. join (",", strArray); // convert an array to a string List <string> list = new List <string> (s. split (','); // string to List string str14 = string. join (",", list. toArray (); // List to string [] str15 = list. toArray (); // convert List to array List <string> listS = new List <string> (str15); // convert array to List Console. writeLine (str0); Console. writeLine (str12); Console. readLine ();}}}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.