SUBSTRING () in C # and Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.