Java Trivia encountered in development

Source: Internet
Author: User

Today in the optimization of a function encountered InStr and substr function, did not contact before these two functions, but today inadvertently used, a check only found, really practical pair of brothers Ah.

First of all, the SUBSTR function, which returns a part of the string.

  SUBSTR (String,start,length)

Where the string parameter is a must parameter, the content of the strings to intercept.

Start is a required argument, the starting position, a positive number, or a negative number, and a positive word represents starting at the specified position in the string; a negative number represents the beginning of the specified position at the end of the string; 0 represents the beginning of the first character in a string.

Length is not a required parameter, and a positive number represents a trailing character from the position where the start parameter is located, and a negative number represents the forward character from the specified position at the end of the string.

As an example:

  substr ("Hello world!", 2, 1) returns the E

substr ("Hello world!", 2) returned is Ello world!

substr ("Hello world!", -2,1) returns D

substr ("Hello world!", -2,-1) returns the d!

  The InStr (string1, string2, start_position,nth_appearance) function returns the position of the string to intercept in the source string.

String1 the source string to find in this string.

String2 the string to find in the string1.

Start_position represents the starting position.

Nth_appearance representative to find the first occurrence of the string2. This parameter is optional, and if omitted, the default is 1. If the system is negative, it will give an error.

As an example:

InStr ("Hello world!", "O") returned is 5

The InStr ("Hello world!", "O", and "8") returned the same. To explain, this sentence represents "O" from the first position of the string to query, the second "O" where it appears.

It's a very useful two function.

  

Java Trivia encountered in development

Related Article

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.