C # And Substring () in Java (),
Vomit... Be sure not to clean up the computer with cleanup software. Otherwise you will be hurt!
Substring () in C ()
Example
Implementation Code
Using System; Using System. Collections. Generic; Using System. Linq; Using System. Text; Using System. Threading. Tasks; Namespace WindowsDemo { Class Program { Static void Main (string [] args) { // Call external functions SubStringDemo (); } // Obtain the sub-string Function Static void subStringDemo () { String str = "123456 "; String subStr1 = str. Substring (5 ); String subStr2 = str. Substring (0, 5 ); Console. WriteLine ("single parameter:" + subStr1 ); Console. WriteLine ("two parameters:" + subStr2 ); Console. ReadKey (); } } } |
Through the example, we can conclude that the input parameters of Substring () are different, and the execution functions are also different.
- When A parameter is passed in, for example, Substring (A) indicates to intercept from the specified index number A of the original string until the last one of the original string;
- When two parameters are passed in, for example, Substring (A, B) indicates that the obtained string length is B starting from the character whose original string index number is;
Note:
If the input parameter is invalid, an ArgumentsOutOfRangeException error is thrown.
Substring () in Java ()
Example
Implementation Code
String str = "123456 "; SubStr = str. Substring (2, 5 ); System. Output. println (subStr ); // Output result 345 |
From the preceding example, we can conclude that:
Str. Substring (A, B) indicates the character from string A to string B, which must contain A, which does not contain B, that is, [A, B ).
Note:
If the parameter is invalid, the IndexOutOfBoundsException error is thrown.