Interception and substitution of C # strings

Source: Internet
Author: User

1. Take the first n characters of a string

(1) String str1=str. Substring (0,n);

(2) String str1=str. Remove (i,str. LENGTH-N);

2. Remove the first n characters of a string

String Str1=str. Remove (0,n);

String Str1=str. SubString (n);

3, start from the right to take n characters:

String Str1=str. SubString (str. LENGTH-N);

String Str1=str. Remove (0,str. LENGTH-N);

4, start from the right to remove n characters:

String Str1=str. Substring (0,str. LENGTH-N);

String Str1=str. Remove (str. LENGTH-N,N);

5. If there is "ABC" in the string, replace it with "ABC"
Str=str. Replace ("abc", "abc");

6. C # intercepts the last character of a string

Str1. Substring (str1. LastIndexOf (",") +1);

7. C # intercepts the last character of a string

str = str. Substring (str. Length-1, 1);

Interception and substitution of C # strings

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.