C # Base------String Functions

Source: Internet
Author: User

            //String Common Functions//1.Contains (contains xx string)//2.StartsWith (whether to start with XX)//3.EndsWith (whether end with XX)//4.IndexOf (Gets the position of the first occurrence of a character in a string)//5.LastIndexOf (Gets the position of the last occurrence of a character in a string)//6.SubString (Intercept string)//7.ToLower (string becomes uppercase)//8.ToUpper (string to uppercase)//9.Replace (Replacement string)//10.Trim (remove the trailing spaces)//Case One: Determine if it is a URL: in http://start with a. com end            /*string s = "http://www.baidu.com";            if (S.startswith ("http://") && s.endswith (". com")) {Console.WriteLine ("Legal url");            } else {Console.WriteLine ("Illegal url");            } console.readkey (); */            //case TWO: Determine if the mailbox is a valid user name has a sensitive vocabulary            /*String name = "Long live XXX";            string email = "[email protected]"; if (name. Contains ("Deng Xiaoping") | | Name.            Contains ("chairman")) {Console.WriteLine ("User name has sensitive words!"); } else if (email.            EndsWith ("@qq. com")) {Console.WriteLine ("QQ Mailbox not supported!");            } else {Console.WriteLine ("Registered successfully!");            } console.readkey (); */            /*string a = "ABCDEEADSA";            Console.WriteLine (A.indexof (' e '));            Console.WriteLine (A.indexof ("CD"));             Console.WriteLine (A.lastindexof (' a ')); */            /*string a = "http://www.baidu.com: 8080 ";            Console.WriteLine (a.substring (0, 5));            Console.WriteLine (A.substring (4));            Console.readkey (); */            //case Three: Get the file name and suffix name            /*string fileName = "[ads-108] Cang jing empty. avi";            int dotindex = Filename.indexof ('. ');            String name = filename.substring (0, Dotindex);            Console.WriteLine (name);            String h = filename.substring (Dotindex + 1);            Console.WriteLine (h);            String a = filename.substring (0, Filename.lastindexof (') ') + 1);             Console.WriteLine (a); */            //Exercise one: from thehttp://www.rupeng.com: 8090/a.htm "Get domain name and port number            /*string yu = "http://www.rupeng.com: 8090/a.htm "; String y = Yu. Substring (Yu. IndexOf (' W '), Yu.            LastIndexOf (': ')-7); int L = Yu.            LastIndexOf ('/'); String d = Yu. Substring (0, Yu.            LastIndexOf ('/'));            string D1 = d.substring (D.lastindexof (': ') +1);            Console.WriteLine (y);            Console.WriteLine (D1);             Console.readkey (); */            /*string a = "HELLO";            String B = A.tolower ();//Generate a new string Console.WriteLine (b);            Console.readkey (); */            /*string a = "Hello";            String r = A.replace (' l ', ' l ');            Console.WriteLine (R);            Console.readkey (); */            /*string a = "leader";//The String object is immutable, but the declaration cannot change string b = A.replace ("leader", "* * *");            Console.WriteLine (b);            Console.readkey (); */            stringA ="I'm"; stringb =A.trim ();            Console.WriteLine (b); Console.readkey ();

C # Base------String Functions

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.