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)