Maybe everyone who is doing character processing will use the string truncation function. Here I am talking about it. the string truncation function SubString () in net c # Is not in other languages. Please take a look at it.
It is mainly a common method of the String class. It is reloaded once, that is, there is a parameter and two parameters. See the following:
1. --------------- public string Substring (int startIndex );
2 ...... public string Substring (int startIndex, int length );
It is easy to understand the first function, that is, to extract all the strings from a certain position. For example, "abcdefg". Substring (2 );
Result: cdefg
"Abcdefg". Substring (1); Result: bcdefgs
Although the 2nd functions are a little more complex, they are quite simple and look at the two parameters, Microsoft's naming method. StartIndex: Start position (index indicates index, location, serial number). length indicates the length of the character to be truncated or the length of the character to be truncated after the original string start position.
DEMO:
Console. WriteLine ("abcdefg". Substring (2, 3 ));
Result: cde
Note: When using this truncation function, first, startIndex cannot be greater than the total length of the character or be less than 0. Otherwise, an error out of the range is reported.
Second, when using the 2nd overload truncation functions, the length cannot exceed the length of the string after the position to be intercepted. For example, the total length of the above string is 7, and the truncation string starts from 2. There can only be five, so it cannot be greater than 5. It cannot be a negative number.
These two methods are common methods of the string class, not static methods of the class, so they can be used only when instantiated. By default, the string is an instance of the class.
This is purely personal notes. It helps you to study in the future.