C # String

Source: Internet
Author: User

Reference type string commonly used for

1. Determine if a string is included

String A= "I ABCDEFG Love You";

Contains ("string");

BOOL Result=a.contais ("ABCDEFG")

Returns: true;

2. Splitter Split intercept field

String b= "ABCDEF&FGHIJ&KLMN";

string [] C=b.split ("&");

C[0]= "ABCdef";

C[1]= "Fghij";

C[2]= "KLMN";

3. Methods for connecting strings.

3.1 Concat

String stra= "Hello";

String strb= "world!";

String Newstr= ""; Here by the way remind yourself of string str=null;string str= ""; In a word, the former does not allocate memory, and the latter opens up a "" memory space for Str.

Newstr=concat (Stra, "", STRB);

Output value: Hello world!

3.2Join

String stra= "Hello";

String strb= "world!";

String Newstr= "";

String[] A={STRA,STRB};

Newstr=string.join ("", a);

Output value: Hello word!

3.3 "+" it's not going to be said, because it's got to come together.

4. There is a split has the connection pit is also inserted insert (int insertindex,string value), the index is starting from 0

4.1 String stra= "Hello";

String strb= "world!";

String Newstr= "";

Newstr=stra. Insert (1,STRB);

Output value: Hworld!ell

5. Delete Remove () deletes the specified number of characters starting at the point where the string was established.

Remove (int stratindex,int count)

String stra= "Hello";

String Newstr= "";

Newstr=stra. Remove (1,3);

Output value: Ho

Also remembered A, Trim (); TrimStart (); TrimEnd (); Remove the empty string.

6. Replacing replace ();

Replace (char Oldchar,char Newchar);

String stra= "Hello";

String Newstr= "";

Newstr=stra. Replace ("ll", "R");

Output: Hero

7. Change the case

ToUpper ();

ToLower ();

    

       

    

C # String

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.