Categories
Coding

XtScript Function: strstr and stristr

strstr is an XtScript function to return a part of string started from the certain first occurrence of the case-sensitive substring passed in the needle argument found.

If you want the function to treat the substring passed in the needle argument as case-insensitive, you can use XtScript stristr function instead.

XtScript strstr and stristr function basic syntax:

<!--parser:xtscript-->
  # Return a part of the haystack from the case-sensitive needle
  call strstr $haystack=...; $needle=...; $before_needle=...
  # Return a part of the haystack from the case-insensitive needle
  call stristr $haystack=...; $needle=...; $before_needle=...
<!--/parser:xtscript-->

Available arguments in XtScript strstr and stristr function:

List of arguments in XtScript strstr and stristr function
Arguments Value Mandatory Explanation
$haystack string Required Specify the main string.
$needle string Required Specify the substring where a part of the main string will be returned started from.
$before_needle 0 (false) or 1 (true) Optional Specify which part of the main string will be returned after the substring ($needle) found, after or before the needle. If this argument is not passed, then the default value will be 0.

Learn XtScript strstr and stristr function from examples

Return a part of the string from after the first occurrence case-sensitive needle found, needle included.

  <!--parser:xtscript-->
    var $string = XtScript and xtgem is an XTreme combination!
    var $ne = xt
    var $partial = call strstr $haystack=$string; $needle=$ne; $before_needle=0
    print String: $string <br/>
    print Partial: $partial
  <!--/parser:xtscript-->
  
String: XtScript and xtgem is an XTreme combination!
Partial: xtgem is an XTreme combination!

Return a part of the string from before the first occurrence case-insensitive needle found, needle excluded.

  <!--parser:xtscript-->
    # Assigning space into variable using chr function so we can use space as the last character in print
    var $spa = call chr $val=32
    var $string = Whether it is Xtscipt code or PHP CODE, all Code are fun to learn!
    print String: $string <br/>
    print Partial:$spa
    call stristr $haystack=$string; $needle=CoDe; $before_needle=1
  <!--/parser:xtscript-->
  
String: Whether it is Xtscipt code or PHP CODE, all Code are fun to learn!
Partial: Whether it is Xtscipt

By SiDar

Webmaster Assistant and Editor at Indotechboy.com.

SiDar enjoying himself listening J-pop genre music and playing games, especially old school games. Sometimes he also found watching anime and reading manga are interesting when his fellow author recommend him some good titles.

Leave a Reply

Your email address will not be published. Required fields are marked *