Method of using string interception in C # (GO)

Source: Internet
Author: User

String substring (int beginindex)
String substring (int beginindex, int endIndex)
string.substring (Int32)The substring starts at the specified character position.
string.substring (Int32, Int32)The substring starts at the specified character position and has the specified length.
Examples are as follows:
string s = "Hello C # world!";
The S1 is the character string after which the position is truncated from S to 3, and 3 indicates the starting character position of the substring.
String s1=s.substring (3);
The S2 is a 6-character string that is truncated from S, and 6 represents the starting character position of the substring, and 2 indicates the length of the substring.
String s2 = s.substring (6, 2);
The results are as follows:
Lo C # world!
C #

int indexOf (String str) returns the index of the specified substring that first appears in this string.
int indexOf (String str, int fromIndex) Returns the index of the first occurrence of the specified substring in this string, starting at the specified index.
int lastIndexOf (String str) returns the index of the specified substring that appears at the rightmost of this string.
int lastIndexOf (String str, int fromIndex) searches backwards at the specified index, Returns the index of the specified substring that last occurred in this string.
int Length () returns the length of this string.
Boolean startsWith (string prefix) tests whether this string starts with the specified prefix.
Boolean startsWith (string prefix, int toffset) tests whether this string starts with the specified prefix, starting at the specified index.
For example:
   string  str=  "C:\\Documents and settings\\administrator\\ desktop \\new1.jpg"
Str. Substring (0,str. LastIndexOf ("\ \") +1) + "new" +str. Substring (str. LastIndexOf ("\ \") +1,
  str. LastIndexOf (".") -str. LastIndexOf ("\ \")-1) +str. Substring (str. LastIndexOf ("."), str. Length-str.lastindexof (".")

Str. LastIndexOf ("\ \")--Get the index value of the last "\ \"
Str. Substring (0,str. LastIndexOf ("\ \") +1)--Get c:\\documents and settings\\administrator\\ desktop \ \
Str. Substring (str. LastIndexOf ("\ \") +1,str. LastIndexOf (".") -str. LastIndexOf ("\ \")-1)--Get New1
Str. Substring (str. LastIndexOf ("."), str. Length-str.lastindexof (".")--get. jpg

Method of using string interception in C # (GO)

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.