Spit Groove ... Use clean software to organize the computer to be careful, do not clean the "too hard", or you will be injured!
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) { Calling external functions Substringdemo (); } Take a substring 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 (); } } } |
With the example, we can conclude that the parameters of substring () are not the same, and the functions performed are different.
- When a parameter is passed in, such as substring (a) means that it is intercepted from the specified index number a of the original string until the last of the original string;
- When passing two parameters, such as substring (A, a, a, a, a, b) indicates that a character starting from the original string index number A is taken, and the string length obtained is B.
Attention
A argumentsoutofrangeexception error is thrown when an incoming parameter is not valid.
SUBSTRING () in Java
Example
Implementation code
String str= "123456"; Substr=str. Substring (2,5); System.Output.println (SUBSTR); Output results 345 |
We can conclude from the above example that:
Str. A Substring (A, A, b) that represents a substring that takes a string of str strings from the ordinal A to the character of a, and satisfies that contains a does not contain B, that is, [b].
Attention
If the argument is not valid, a indexoutofboundsexception error will be thrown.
SUBSTRING () in C # and Java