Truncate string Partial Summary

Source: Internet
Author: User

The interception of strings is a very small method that is often used in development, but because many local indexes are easily confused by the 0/1 contention. Record a few of the known uses.

    • The substring () method in Java

(1) xx.substring (int begin) intercepts the content starting at the specified position to the end of the character.

(2) xx.substring (int begin,int end) intercepts the character content between the specified start index and the end index. ( the intercepted content contains begin does not contain end)

Note : Begin is starting at 0. The number that is intercepted when the character is intercepted .

① if the value of start and end is equal, an empty string is returned.

② if the setting is begin set to a negative number will be error java.lang.StringIndexOutOfBoundsException:String in Dex out of Range:xx

    • SUBSTRING () method in SQL Server database

(1)SUBSTRING (expression,begin,length ) intercepts the length of a character starting at the specified position. (intercept contains begin position)

Note : Begin is starting at 1 . If the begin is set to 0 then the truncated result will be one less than the length setting, which is equivalent to intercepting the length-1, and begin allows for a negative value to be set.

    • Oracle Database substr () method

(1) substr (string, Begin, [ length ]) intercepts the length of the character starting at the specified position, and the length of the setting can be selected. If the value of length is not specified, all content after the start of begin is intercepted.

If a negative number is intercepted from behind, 1 refers to the last character in the string, 2 refers to the second-to-penultimate character, and so on.

Note:begin is starting at 1. Begin, whether set to 0 or 1, is intercepted from the first character, which is separated from the substring area in SQL Server and allowed to be set to a negative number.

    • The substr () method in JavaScript

     (1) xx.substr (start,length) Start is the starting subscript for the extracted character, the index of start starting from 0, intercept characters of length.

If a negative number is intercepted from behind, 1 refers to the last character in the string, 2 refers to the second-to-penultimate character, and so on.

Note:the index of start starts at 0 and is allowed to be set to a negative number.

    • javascript

(1) xx.substring (start,end) Start is the starting subscript of the extracted character, starting at index 0, and its contents are all characters from start to stop-1. (contains start does not contain end)

Note: The following three points are more special, you need to pay attention to.

                ① If the value of start and end is equal, an empty string is returned.

                 If start is larger than end, the method will exchange the two parameters before extracting the substring.

                 If start or end is negative, it will be replaced with 0.

Truncate string Partial Summary

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.