XtScript Function: substr
Returns a part of a string from certain position and for certain length.
substr is an XtScript function that can trim / cut a string from a specific character index position, for certain length, and return the result.
XtScript substr function basic syntax:
<!--parser:xtscript--> call substr $val=...; $start=...; $length=... <!--/parser:xtscript-->
Available arguments in XtScript substr function:
Arguments | Value | Mandatory | Explanation |
---|---|---|---|
$val | string | Required | Specify the main string. |
$start | number | Required | Specify the index of character the string will be trimmed / cut started from. If the value is negative, the function will started work from the position from the end of the string. |
$length | number | Optional | Specify the length of the returned string. If this argument is not set, then it will return all remained characters until the end of the string. |
Learn XtScript substr function from examples
Trim a string for started from specific position, for certain length.
- Code:<!--parser:xtscript--> var $string = I am learning XtScript right now! var $string_2 = call substr $val=$string; $start=5; $length=17 var $message = XtScript is fun to learn, isn't it? var $message_2 = call substr $val=$message; $start=-9 print String: $string <br/> print After substr : $string_2 print <br/><br/> print Message: $message <br/> print After substr: $message_2 <!--/parser:xtscript-->- Result:
String: I am learning XtScript right now!
After substr : learning XtScript
Message: XtScript is fun to learn, isn't it?
After substr: isn't it?
After substr : learning XtScript
Message: XtScript is fun to learn, isn't it?
After substr: isn't it?
Last edited on