The difference and function of substr(), substring(), slice(), split(), split()

substr(start ,length)

Used to intercept a string, the parameters of substr() specify the starting position and length of the substring, and the return value is a new string, the original string has not changed, so it can be used instead of substring() and slice() .

substring(start,stop)

Used to intercept a string, start and stop are the start and end positions, respectively, and the return value is a string, which includes the element at the start position but not the element at the stop position.

slice(start,end)

This method is a partial interception of the array. The method returns a new array. The parameter start is the index of the starting array to intercept, and the end parameter is equal to the position value of the last character you want to take plus 1 (optional). Contains the elements specified by the source function from start to end, but does not include the end element, and will not change the original array.

splice(start,deletecount,item)

The method is to remove one or more arrays from the array and replace them with new items. start represents the starting position, deletecount represents the number of bits to delete, the replaced item, the return value is the deleted string, if there are additional parameters, then the item will be inserted at the position of the removed element. The original value has changed.

split (string)

string.split(separator,limit), the split method splits this string into fragments to create a string array. The optional parameter limit can limit the number of fragments to be divided. The separator parameter can be a string or a regular expression. If the separator is a null character, it will return a single-character array without changing the original array.

Guess you like

Origin blog.csdn.net/weixin_49549509/article/details/108438737