C # takes advantage of String class indexof, LastIndexOf, substring to intercept strings

Source: Internet
Author: User

First, String.IndexOf

String.IndexOf method (Char, Int32, Int32)
Reports the index of the first occurrence of the specified character in this instance ( starting at 0 ). The search starts at the specified character position and checks the specified number of character positions.
String.IndexOf (value, StartIndex, Count)

Parameters
Value: The Unicode character to find.
StartIndex: Search start location.
Count: The number of character positions to check.
return value (INT32):
The index position of value if the character is found, or 1 if not found.

Second, String.LastIndexOf

String.LastIndexOf method
Reports the index position of the last occurrence of the specified Unicode character or String in this instance.

Third, string.substring

String.substring method
Retrieves a substring from this instance.

Name Description
String.substring (Int32) Retrieves a substring from this instance. The substring starts at the specified character position.
String.substring (Int32, Int32) Retrieves a substring from this instance. The substring starts at the specified character position and has the specified length.

Example: File contents

1$aid_700e5984dba96744
2$aid_b5f0d8ca79ae856e#aid_700e5984dba96744
3$aid_2f0b6558766df9b6#aid_b5f0d8ca79ae856e

C # takes advantage of String class indexof, LastIndexOf, substring to intercept 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.