C # How to Implement left and right truncation strings in winform
The substring method provided in C # can implement related functions.
First, let's review the substring method.
Usage 1: String. substring method (startindex, length)
Returns the child string of length starting with startindex in this string.
Startindex: Index of the starting position of the substring, starting from 0.
Length: the number of truncated characters in the substring.
Usage 2: String. substring method (startindex)
Returns all the remaining characters starting from startindex in the string.
Startindex: Index of the starting position of the substring, starting from 0.
After getting familiar with this method, we will implement how to extract strings left and right.
Left truncation: Str. substring (0, I) returns, and returns the I characters on the left.
Right truncation: Str. substring (Str. Length-I, I) returns, and returns the I characters on the right.
See the following example:
Int I = 2;
String STR = "123456 ″;
String strleft = Str. substring (0, I );
String strright = Str. substring (Str. Length-I, I );
Strleft is "12 ″
Strright is "56 ″