String.slice

String.slice

String.slice

Function

Cut the string according to the starting and ending positions.

Syntax

Parameters

ParametersTypeRequiredDefault valueDescription
startIntNo0Starting character position; a negative number means counting backwards from the end.
endIntNoString lengthThe end character position, excluding this position; a negative number means counting backwards from the end.

Return value

TypeDescription
StringReturns the new string after interception.

Example

Notes

  • Truncate according to character position and will not cut off UTF-8 characters.
  • Returns an empty string when start is greater than or equal to end.