Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use substr function in jquery

Shulou Source: shulou.com Published: 2022-06-01 04:11:01 10月12日 Update

This article is about how to use the substr function in jquery. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In jquery, the substr function is used to intercept a substring of a specified number of characters starting from the specified subscript of a string. The function supports two arguments, the first parameter specifies the starting subscript to be intercepted, and the second parameter specifies the number of characters; the syntax "string object .substr (start,length)".

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, the substr function is used to intercept a specified number of characters starting with the specified subscript of a string. This intercepted character can be called a "substring" or "substring". The syntax format is as follows:

The stringObject.substr (start,length) parameter is required to describe start. The starting subscript of the substring to be extracted. Must be a numeric value. If it is a negative number, this parameter declares the position from the end of the string. That is,-1 refers to the last character in the string,-2 refers to the penultimate character, and so on. Length is optional. The number of characters in the substring. Must be a numeric value. If this parameter is omitted, the string from the beginning to the end of the stringObject is returned.

Return value:

A new string containing length characters starting at the start of stringObject (including the characters referred to by start). If length is not specified, the returned string contains the characters from start to the end of stringObject.

Example: intercept the string "Hello world!" starting with subscript 5 and intercept 6 characters

$(document) .ready (function () {var text=$ ("p"). Text (); console.log (text.substr (5));})

Hello world!

Thank you for reading! This is the end of the article on "how to use the substr function in jquery". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Characters strings parameters functions subscript position content numeric value more article syntax start good practical and so on two that is object tail Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Shulou Information MySQL MariaDB